Question

In: Computer Science

In Rars RIsc V Write a program that lets you enter a string. Maximum length 50.Then,...

In Rars RIsc V

Write a program that lets you enter a string.

Maximum length 50.Then, perform the sorting algorithm sort it in regards of the ascii values.

Print the string BEFORE and AFTER the sort in separate rows.

Solutions

Expert Solution

Written these code /program in python:

write program for string of maximum length 50.and also the output i.e. without sorting (before sort)

• sorting algorithm sort in regards of ascii value.

•print a string after sort in separate rows.

#Python code to demonstrate the working of string

#Working of sort string by maximum length of the string is 50G

#​​​​​GetMaximum char fnc.

def get_max(sub):

#Return Maximum character

return ord ( max ( sub ))

#initializing list

test_list = [ " geeksforgeeks " , "is" , " best", "for ","cs"  ​​​​​]

#printing original list

print (" the original list is:" + str (test_list))

#printing result

print (" the list is:" + str​​​​str(test_list))

output: (before the sorting)

the original list is : ["geeksforgeeks" , "is", "best" ,"for","cs" ]

The sorting algorithm sort It in regards of ascii value;

Input : test_list =["geeksforgeeks","is","best"]

Output: test_list =["geeksforgeeks","is","best"]

Explaination: s=s=s<t , sorted by maximum character.

Input: test_list= [" apple","is", fruit"]

output: test_list = ["apple","is","fruit"]

​​​​​​Explaination: p<s<t, hence order retained after sorting by max character.

Code after sorting ;

#above code after sorting the value

def get_max (sub):

return ( ord (max (sub))

test_list = [" geeksforgeeks","is", "best" , "for" ,"cs"  ]

print (" the original list is:" + str (test_list))

#performing sorting

test_list.sort (key= get_max)

#printing result

print (" sorted list is" : + str (test_list))

output (after sorting):

Original list is: ["geeksforgeeks","is" ,"best" , " for" ," cs" ]

Sorted list is: [" for" , "geeksforgeeks, "is" , "cs" , "best" ]


Related Solutions

How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. ‘+’ and ‘-’ will appear optionally. And once they appear, they will only appear once in the first byte. If a non-digit character appears in the string, your program should stop and return -1.
C++ Write a program that lets the user enter a two letters which are f and...
C++ Write a program that lets the user enter a two letters which are f and s with a length of 5. And outputs how many times it was occurred and lists the 2 most repeating pattern with 5lengths of f and s. The output display should always start at three-f(s) .Include an option where user can retry the program. Example: Input: sssfsfsfssssfffsfsssssfffsffffsfsfssffffsfsfsfssssfffffsffffffffffffssssssssfffsffffsssfsfsfsfssssfffsssfsfsffffffssssssffffsssfsfsfsss Output: The most repeating 5lengths of pattern is: fffsf and occurred 6times. Output2: The second most repeating...
Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
Write a program that lets the user enter the loan amount, number of years, and interest...
Write a program that lets the user enter the loan amount, number of years, and interest rate and displays the amortization schedule for the loan. Steps: 1) Create scanner 2) Prompt the user to enter loan amount and declare double variable and relate to scanner input 3) Prompt the user to enter number of years and declare integer years and relate to scanner input 4) Prompt the user to enter annual interest rate and declare double variable and relate to...
Write a java program that lets the user to enter any two integers and weave them...
Write a java program that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of...
In a file called LengthSum.java, write a program that: Asks the user to enter a string....
In a file called LengthSum.java, write a program that: Asks the user to enter a string. Asks the user to enter a second string. Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please enter a second...
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string....
In a file called FourCapitalizations.java, write a program that: Asks the user to enter a string. Prints out four different versions of that string: The original version of the string. The upper-case version of the string. The lower-case version of the string. A version where the character at position 0 capitalized, and all other characters in lower case. For example: if the user enters string "gaNDalF12 !! AB3w", your program output should look EXACTLY like this: Please enter a string:...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
Write a python program that asks the user to enter a string containing numbers separated by...
Write a python program that asks the user to enter a string containing numbers separated by commas, e.g., s = '1.23,2.4,3.123', Your program should then calculate and print the sum of the numbers entered. Hint: you need to iterate over the string searching for the commas, i.e. their index. The first number is obtained by slicing between the start of the string and the index of the first comma. The second number is between the last comma and the next...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT