Word Reversal

来源:互联网 发布:php 魔术方法 编辑:程序博客网 时间:2024/05/17 23:34

For each list of words, output aline with each word reversed without changing the order of the words.


This problem contains multiple test cases!

The firstline of a multiple input is an integer N, then a blank line followed by N inputblocks. Each input block is in the format indicated in the problem description.There is a blank line between input blocks.

Theoutput format consists of N output blocks. There is a blank line between outputblocks.


Input

You willbe given a number of test cases. The first line contains a positive integerindicating the number of cases to follow. Each case is given on a linecontaining a list of words separated by one space, and each word contains onlyuppercase and lowercase letters.


Output

For eachtest case, print the output on one line.


Sample Input

1

3
I am happy today
To be or not to be
I want to win the practice contest


Sample Output

I mayppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc


【思路】:没有用调用函数,直接强行遍历的算。

1.输入一行数据,要用cin.getline(x,n)x是类型名,后面n的大小。getline头文件是stdio.h

2.注意getchar的使用

3.自己犯了脑残错误,=和==搞混,菜啊。。。。


#include<iostream>#include<string.h>                                                          //   strlen的头文件!!                                                          #include<stdio.h>                                                           //   getline的头文件!!!using namespace std;int main(){int n,i,j,k,l;char words[1024];cin>>n;getchar();                                                           //从这一行还是输入字符串,不然前面3也算。for(i=0;i<n;i++){                                                    //输入行数cin.getline(words,1024);l=strlen(words);                                             //输入字符串长度int index=0,flag=0,temp=0;for(j=0;j<l;j++){if(words[j]==' '){                                  //遇到空格temp=j;for(k=temp-1;k>=index;k--){cout<<words[k];}cout<<" ";index=temp+1;flag=1;}if(j==l-1){                                          //最后一个空格if(flag){                                    //注意这点,标示用了没有。for(k=l-1;k>=index;k--){cout<<words[k];}}else{for(k=l-1;k>=0;k--){cout<<words[k];}}}}if(i!=n-1) cout<<endl;}return 0;}


原创粉丝点击