欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > 数据结构,问题 A: 翻转字符串

数据结构,问题 A: 翻转字符串

2025/2/21 3:08:40 来源:https://blog.csdn.net/nick_912912/article/details/143418999  浏览:    关键词:数据结构,问题 A: 翻转字符串
题目描述

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. 

Ignatius 喜欢用相反的方式写字。给定 Ignatius 编写的单行文本,您应该反转所有单词,然后输出它们。 

输入 

输入包含多个测试用例。输入的第一行是一个整数 T,它是测试用例的数量。T 测试用例紧随其后。 每个测试用例都包含一行和多个单词。一行最多有 1000 个字符。 输出

 对于每个测试用例,您应该输出经过处理的文本。

输入

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a single line with several words. There will be at most 1000 characters in a line.

输出

For each test case, you should output the text which is processed.

样例输入 复制
3
olleh !dlrow
m'I morf .udh
I ekil .mca
样例输出 复制
hello world!
I'm from hdu.
I like acm.
提示

Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

#include<bits/stdc++.h>
using namespace std;stack<char> q;void print(){while(!q.empty()){cout << q.top();q.pop();}
}int main(){int n;cin >> n;cin.ignore();while(n > 0){string s;getline(cin, s);for(char c : s){if(c == ' '){print();cout << ' ';}else {q.push(c);}}print();cout << '\n';n --;}return 0;
}

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词