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 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...
Convert the following C program into the RISC-V assembly code. You should look up a table...
Convert the following C program into the RISC-V assembly code. You should look up a table to convert the lines manually and you can use "ecall" when appropriate (Don't make it too complicated than it needs to be): #include int main() { int x = 30, y = 17; printf("x * y = "); printf("%d\n", x*y); return 0; }
Checker for integer string Forms often allow a user to enter an integer. Write a program...
Checker for integer string Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the output is: no Hint: Use a loop and the Character.isDigit() function. import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr...
In Python: Design a program that lets the user enter the total rainfall for each of...
In Python: Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing...
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts...
Write an 8088/8086 assembly program that counts the length of a null terminated string that starts at location STR.Assume string length will not exceed 255 character.Print the result on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT