Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write code 7. Mario Program Name: Mario.java Input File: mario.dat Mano is trying to create a new way to write words in code so

Please write code
image text in transcribed
7. Mario Program Name: Mario.java Input File: mario.dat Mano is trying to create a new way to write words in code so he can leave secret messages to his friends. He has come up with an interesting way to encode a word. A word will be accompanied by an integer. That integer indicates how many letters at the front and at the back of a word that will be swapped. For example, if the integer is 2 and the word is COMPUTER, the first two letters of COMPUTER "CO" will be placed at the end of the word and the last two letters "ER" will move to the front. But, to make it just a bit trickier, Mario will reverse the letters in each of the two blocks that are being swapped. Thus, in the example above "OC" moves to the end and "RE" moves to the start. 2 COMPUTER gives us REMPUTOC 3 COMPUTER gives uS RETPUMOC Mario noticed that there would be two special cases. If the integer is larger than the number of letters in the word, the output is "enror". 7. MOUSE gives us error If the integer does not trigger an error as mentioned above, but is more than half the length of the word, the result would be simply the reversal of the original word. 4 TEXAS gives us SAXET Write the program to allow Mario to encode his words. Input: Input will consist of an integer N, the number of test cases. The number of test cases will be in range [1,20]. Each subsequent line will contain one integer in the range [1,100] followed by one space then a string consisting only of upper-ease letters. The strings will contain no spaces and no punctuation marks. The string will be of length [1,100]. Output: Each line of output will consist of one string of characters representing the "rearranged" solution. If the inputs ereate an error code mentioned above, the output will be "error" written in all lower-case letters. Sample input: 5 3 ABCDEFG 4 AB 1 ABCDEFG 5 OWERTY 2 ASDEGH Sample output: GEEDCBA exror GBCDEFA YTREWQ HGDESA

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions