TOj 1153. Word Reversal【栈】

1153. Word Reversal

Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 8475 Accepted Runs: 3096 Multiple test files



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


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

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
using namespace std;
int iszimu(char ch)
{
	if('a'<=ch&&ch<='z'||'A'<=ch&&ch<='Z')
	{
		return 1;
	}
	return 0;
}
int main()
{
	int t;
//	freopen("shuju.txt", "r", stdin);
	scanf("%d", &t);
	getchar();
	while (t--)
	{
		char ch;
		stack < char >x;
		while ((ch = getchar()) != '\n')
		{
			if (iszimu(ch))
			{
				x.push(ch);
			}
			else if (!x.empty())
			{
				while (!x.empty())
				{
					printf("%c", x.top());
					x.pop();
				}
				printf("%c", ch);
			}
			else
			{
				printf("%c", ch);
			}
		}
		while (!x.empty())
		{
				printf("%c", x.top());
				x.pop();
		}
		printf("\n");
	}
	return 0;
}




你可能感兴趣的:(栈)