1151_Word Reversal

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


This problem contains multiple test cases!

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

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


Input

You will be given a number of test cases. The first line contains a positive integer indicating the number of cases to follow. Each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.


Output

For each test 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 ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc


××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××


#include<iostream>

#include<string>
using namespace std;
int main()
{
string line;
int count=0;
int num;
int num_1;
cin>>num;
for(int m=0;m!=num;++m)
{   
cin>>num_1;
for(int n=0;n!=num_1+1;++n)//循环次数少一次,怎么回事?
{
getline(cin,line);
if(n==0)//输入num_1后,然后又一个换行符,将此行掠过,浪费一个getline();所以n!=num_1+1;比正常大一。
  continue;
for(int i=0;i!=line.size();i++)
{
if(line[i]==' ')
{
for(int j=i-1;j>=count;j--)
cout<<line[j];
cout<<' ';
count=i+1;
}
if(i==line.size()-1)
{
for(int j=i;j>=count;j--)
cout<<line[j];
}
}
cout<<endl;
count=0;
cin.clear();
}
if(m!=num-1)
  cout<<endl;
}




return 0;
}
//c++ string getline()函数
//一个有用的string IO操作:getline。这个函数接受两个参数:一个输入流对象和一个string对象。getline函数从输入流的下一行读取,并保存读取的内容到 string中,但不包括换行符。和输入操作符不一样的是,getline并不忽略行开头的换行符。只要getline遇到换行符,即便它是输入的第一个 字符,getline也将停止读入并返回。如果第一个字符就是换行符,则string参数将被置为空string。
//getline函数将istream参数作为返回值,和输入操作符一样也把它用作判断条件。
//由于line不含换行符,若要逐行输出需要自行添加。照常,用endl来输出一个换行符来刷新输出缓冲区。
//注解:由于getline函数返回时丢弃换行符,换行符将不会存储在string对象中。
//摘自《c++ Primer》
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值