Single File Programming QuestionProblem StatementDavid is working on a project that involves processing alphanumeric data from various sources. He needs a program to organize the uppercase letters in the given data and calculate the sum of numeric values. David believes that this arrangement will help him quickly identify patterns and numeric trends in the data.Write a program that takes a string as input, arranges the uppercase letters in alphabetical order, and provides the sum of all numeric digits present in the string.ExampleInput: AC2BEW3Output: ABCEW5Explanation:The output prints the alphabet in lexicographic order, followed by the sum of integers (2 and 3).Input format :The input consists of a string S containing characters and integer values.Output format :The output displays the uppercase letters sorted alphabetically, followed by the sum of all numeric digits present in the string.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:5 ≤ length of each string ≤ 15Sample test cases :Input 1 :AC2BEW3Output 1 :ABCEW5Input 2 :Z2X5C1V4BN123Output 2 :BCNVXZ18Input 3 :K8L5MOutput 3 :KLM13Input 4 :DataScience2022Output 4 :DS6Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Question
Single File Programming QuestionProblem StatementDavid is working on a project that involves processing alphanumeric data from various sources. He needs a program to organize the uppercase letters in the given data and calculate the sum of numeric values. David believes that this arrangement will help him quickly identify patterns and numeric trends in the data.Write a program that takes a string as input, arranges the uppercase letters in alphabetical order, and provides the sum of all numeric digits present in the string.ExampleInput: AC2BEW3Output: ABCEW5Explanation:The output prints the alphabet in lexicographic order, followed by the sum of integers (2 and 3).Input format :The input consists of a string S containing characters and integer values.Output format :The output displays the uppercase letters sorted alphabetically, followed by the sum of all numeric digits present in the string.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:5 ≤ length of each string ≤ 15Sample test cases :Input 1 :AC2BEW3Output 1 :ABCEW5Input 2 :Z2X5C1V4BN123Output 2 :BCNVXZ18Input 3 :K8L5MOutput 3 :KLM13Input 4 :DataScience2022Output 4 :DS6Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Solution
Here is a Python solution for the problem:
def process_data(data):
# Initialize variables
sum = 0
letters = []
# Iterate over each character in the data
for char in data:
# Check if the character is a digit
if char.isdigit():
# Add the digit to the sum
sum += int(char)
# Check if the character is an uppercase letter
elif char.isupper():
# Add the letter to the list of letters
letters.append(char)
# Sort the letters
letters.sort()
# Return the sorted letters and the sum
return ''.join(letters) + str(sum)
# Test the function
print(process_data('AC2BEW3')) # Output: ABCEW5
print(process_data('Z2X5C1V4BN123')) # Output: BCNVXZ18
print(process_data('K8L5M')) # Output: KLM13
print(process_data('DataScience2022')) # Output: DS6
This program works by iterating over each character in the input data. If the character is a digit, it is added to the sum. If the character is an uppercase letter, it is added to a list of letters. After all characters have been processed, the list of letters is sorted and concatenated with the sum to produce the final output.
Similar Questions
Single File Programming QuestionProblem StatementMithun is developing a program for a data collection tool that allows the user to input a series of positive integers until they enter a negative value. The program should dynamically allocate memory for an integer array to store these numbers using the new operator. The program should then calculate and display the sum and average of the entered integers. Write a program to accomplish this task.Note: This kind of question will help in clearing HCL recruitment.Input format :The input consists of positive integers separated by a space. It continues until a negative value is entered.Output format :The first line of the output displays the entered numbers.The second line displays the sum of the numbers.The third line displays the average of the entered numbers.Refer to the sample output for formatting specifications.Code constraints :numbers > 0Maximum number <=100Sample test cases :Input 1 :1 2 3 4 5 6 -1Output 1 :Numbers entered: 1 2 3 4 5 6 Sum of entered numbers: 21Average of entered numbers: 3.50Input 2 :10 20 30 40 50 60 70 80 90 100 -4Output 2 :Numbers entered: 10 20 30 40 50 60 70 80 90 100 Sum of entered numbers: 550Average of entered numbers: 55.00Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Single File Programming QuestionProblem StatementNancy, an aspiring programmer, has a series of alphabets from A-Z arranged circularly. Write a program that takes an integer input representing the position in the series and prints the corresponding character. Example: If Miranda inputs 1, it corresponds to 'A'.If Miranda inputs 28, it corresponds to 'B' because the alphabet series is circular, and position 28 loops back to the second letter in the series.Help Nancy by crafting a program that meets her challenge using a recursive function called generateTerm.Input format :The input consists of an integer n, representing the position for which the character needs to be retrieved,Output format :The output prints the character present at the given position.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ n ≤ 100Sample test cases :Input 1 :1Output 1 :AInput 2 :28Output 2 :BInput 3 :59Output 3 :GInput 4 :100Output 4 :VNote :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Single File Programming QuestionProblem StatementImagine Mary is developing a program to calculate the digital root of a positive integer. The digital root of a positive integer is the number obtained by repeatedly summing the digits until a one-digit sum is obtained. For example, for the number 873597, the digital root is calculated in the following steps:-> 8 + 7 + 3 + 5 + 9 + 7 = 39 -> 3 + 9 = 12 -> 1 + 2 = 3 Write a program that will read in a positive integer and write both its digital root and the number of steps required to obtain it.Note: This question was asked in ACM-ISPC contest.Input format :The input consists of a positive integer n.Output format :The first line displays "Digital Root: " followed by the digital root of n.The second line displays "Number of Steps: " followed by the number of steps required to reach a single-digit digital root.Refer to the sample output for the formatting specificationsCode constraints :In the given scenario, the test cases fall under the following constraints:2 ≤ n ≤ 106Sample test cases :Input 1 :123Output 1 :Digital Root: 6Number of Steps: 1Input 2 :2Output 2 :Digital Root: 2Number of Steps: 0Input 3 :873597Output 3 :Digital Root: 3Number of Steps: 3Input 4 :1000000Output 4 :Digital Root: 1Number of Steps: 1
Single File Programming QuestionProblem StatementEmma, a computer science student, is organizing a list of names for a project. She needs a program to input a set of names and arrange them in alphabetical order. She wants to write a program that takes the number of names (n) as input and then receives n names. The program should then arrange the names in alphabetical order and print the sorted list.Emma approached you for help, and you are tasked with creating a program to assist her in achieving this.Input format :The first line consists of an integer N, representing the number of names.The next N lines of input consist of a string in each line, representing the names.Output format :The output displays strings, representing the sorted names in alphabetical order, separated by a line.Refer to the sample outputs for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ N ≤ 103 ≤ Length of each name ≤ 14Sample test cases :Input 1 :5KarthickRamKumarUmaSeethaOutput 1 :KarthickKumarRamSeethaUmaInput 2 :8KlausCatherineeeTylerDamonElenaStefanBonnieElijahOutput 2 :BonnieCatherineeeDamonElenaElijahKlausStefanTylerInput 3 :10WilliamOliviaJamesEmmaLiamAvaBenjaminSophiaMiaShakespeareOutput 3 :AvaBenjaminEmmaJamesLiamMiaOliviaShakespeareSophiaWilliamInput 4 :2EveCharliePuthOutput 4 :CharliePuthEve
Single File Programming QuestionProblem StatementOlivia is a curious mind exploring the world of digits. Create a simple program to assist Olivia in understanding the addition of the last two digits of a given number. Prompt Olivia to input an integer n, calculate, and display the sum of the last two digits.Input format :The input consists of an integer n.Output format :The output displays the sum of the last two digits of the input integer.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:10 ≤ n ≤ 105Sample test cases :Input 1 :10Output 1 :1Input 2 :231Output 2 :4Input 3 :7896Output 3 :15Input 4 :100000Output 4 :0Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.