HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


51246 - Swap largest word, reverse the rest

Volume problems

• 50868 - Sort Frequencies
• 50405 - Accounts Receivable
• 50377 - kth Permutation
• 50908 - Buy 1 Get 1
• 50906 - The Smallest Pair
• 51043 - Genome Sequencing
• 51042 - The most frequent k-mer
• 50657 - Permutations and Combinat...
• 51246 - Swap largest word, rev...
• 51069 - Last Digit of a Fibonacci Nu...
• 50659 - Covariance Matrix
• 50977 - Gaussian Elimination
• Word Puzzle
• 50748 - Gold Store
• 50658 - The Message
• 50766 - Word Puzzle
• 50934 - Selling Cars

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ismail Shpati.

Swap largest word, reverse the rest

Question: A line of text will be given. You will have to do the following modifications to this line of text:

  • Swap the largest word, with the smallest one (smallest word must have more than 2 characters; length > 2).
  • If there are two or more words with the same length, take the first instance.
  • Reverse the rest of the words that have more than 3 characaters (length > 3).
  • There will be punctutation marks at the end of some words (" . " " , " " ! " " ? " " ; " " : "). They shouldn't be calculated in the length of the word.
  • The punctuation mark should remain at the end of the word even if the word is reversed. (ex. word. => drow.)

Input specification: You will be given one line of text. (maximum length of the line 300 characters; maximum length of a word 20 characters)

Output specification: Show the modified line of text (Note: there shouldn't be a space at the end of the line)

Sample Input I
Andy went, to the park.
Sample Input II
Scattering around, did not bring much joy.
Sample Output I
the tnew, to Andy krap.
Sample Output II
did dnuora, Scattering not gnirb hcum joy.

Sample Input I Explanation: At the first input, we have 3 words with the length of 4 which also is the max length (Note: "went" and "park" both have a punctuation mark at the end but it isn't calculated in the length of the word). We take the first instance, which is "Andy" and swap it with "the" which is the smallest word with a length greater than 2. The rest of the words are reversed without moving the punctuation mark. (went, => tnew,)

 
Для отправки решений необходимо выполнить вход.

www.contester.ru