对于一串单词,直接把它们输出在一行上,要把每个单词反转,但每个单词的位置不
要改变。
本程序包含多个测试案例!
输入数据的第一行是一个整数
N
,然后是一空行,后面跟着
N
个数据块。每个数据块
的格式在程序描述中说明了。数据块中有一空行。
输出格式由
N
个输出块组成。每个输出块间有一空行。
2.输入描述
现在给你多组测试案例。第一行是一个正整数,表示接下来的测试案例的个数。每个
测试案例是一行,包含一串单词,中间用一个空格隔开,每个单词仅包含大写和小写字母。
3.输出描述
每个测试案例都打印在一行上。
4.输入样例
1
3
I am happy today
To be or not to be
I want to win the practice contest
5.输出样例
I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
#include "stdafx.h"
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream in("D:\\visual studio 2013 code\\test.txt");
int num;
string str,word;
char temp[80];
in.getline(temp, 80);
in.getline(temp, 80);
in >> num;
char ch;
ch = in.get();
while (ch != '\n')
{
ch=in.get();
}
for (int i = 0; i < num; i++)
{
in.getline(temp, 80);
str = temp;
for (int j = 0; j < str.size(); j++)
{
if (str[j] != ' ')
{
word = str[j] + word;
}
else
{
cout << word << " ";
word = "";
}
}
cout << endl;
}
return 0;
}