SCRAMBLE - SCRAMBLE1

no tags 

 

MOCK PE 2010

Question 2

(This question has been adapted from a CS1010e tutorial)

 

A word is scrambled if, given a word, the first and last letters of the word remain unchanged while the rest of the letters may have their places interchanged.

In this question, we adopt cyclic-scrambling where each letter (except for the first and last) is shifted one place to the right with wrap-around. For example, the word “programming” when cycled once will produce “pnrogrammig”. Notice the letter “n” wraps-around to the second position. When cycled another time the word produced is “pinrogrammg”. Note that the first and last characters always maintain their place.

Write a program that takes in the number of cycles, n, followed by a sentence. The program then proceeds to cyclic-scramble each word in the sentence n times.

You may assume that the length of each word is strictly below 20 characters, and the length of each sentence (aka input) is strictly below 200 characters.

Your program should contain a function ‘cycle’ that takes in arguments of two character strings str1, str2 and an integer value n that performs cycling for n times on str1 with the resulting word stored in str2.

void cycle(char str1[], char str2[], int n);

============================================

Sample 1 (Italicised words are the input, bolded words are the output):

1
According to a research at Cambridge University it does not matter in what order the letters in a word are the only important thing is that the first and last letter be in the right place

Anccordig to a rcesearh at Cgambride Utniversiy it deos not meattr in waht oerdr the lrettes in a wrod are the olny inmportat tnhig is taht the fsirt and lsat leettr be in the rhigt pclae

============================================

Sample Input 2 (italicised words are the input, bolded words are the output):

3
According to a research at Cambridge University it does not matter in what order the letters in a word are the only important thing is that the first and last letter be in the right place

Adinccorg to a rarceseh at Cidgambre Usitnivery it deos not mttear in waht order the lterets in a wrod are the olny itanmport thing is taht the first and lsat ltteer be in the right place

============================================


hide comments
soc: 2010-10-25 12:44:56

Dear all from SoC, you can view the sample solution at the below link:

https://docs.google.com/document/edit?id=1e5pRSCoy25WQ4sjlgEXHMdp6Uv-LU3PSsl7w-R7NGOo&hl=en&authkey=CIGvmeUP

bearing in mind, of course, that there are many solutions to the same problem.

Cheers!
13th MC, Academic Cell


Added by:Zhang Zhiyong Melvin
Date:2010-10-25
Time limit:0.200s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET