Word Scramble
Write a program that will reverse the letters in each of a sequence of words while preserving the order of the words themselves.Word Scramble |
Input
The input file will consist of several lines of several words. Words are contiguous stretches of printable characters delimited by white space.Output
The output will consist of the same lines and words as the input file. However, the letters within each word must be reversed.Sample Input
I love you. You love me. We're a happy family.
Sample Output
I evol .uoy uoY evol .em er'eW a yppah .ylimaf----------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<string.h>
char s[1000005],a[1000005];
int main(){
int i,j,l;
while(gets(&s[1])){
s[0]=' ';
for(i=1;s[i];i++){
if(s[i-1]==' ' && s[i]!=' '){
sscanf(&s[i],"%s",a);
l=strlen(a);
for(j=l-1;j>=0;j--)
putchar(a[j]);
}
if(s[i]==' ') putchar(' ');
}
puts("");
}
}
沒有留言:
張貼留言