当前位置:网站首页>775. 倒排单词
775. 倒排单词
2022-07-28 20:50:00 【Hunter_Kevin】
题目
编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔。
输入格式
输入为一个字符串(字符串长度至多为 100)。
输出格式
输出为按要求排序后的字符串。
输入样例:
I am a student
输出样例:
student a am I
代码
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string s;
getline(cin, s);
stringstream ssin(s);
string tmp;
vector<string> q;
while(ssin >> tmp)
q.push_back(tmp);
while(q.size())
{
cout << q.back() << ' ';
q.pop_back();
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
string str[100];//字符串数组
int n = 0;//标记字符串的个数
while (cin >> str[n]) n ++ ;
//从后往前输出每个字符串
for (int i = n - 1; i >= 0; i -- ) cout << str[i] << ' ';
cout << endl;
return 0;
}
边栏推荐
- Mysql内置函数
- Less than a year after its establishment! MIT derivative quantum computing company completed financing of US $9million
- Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
- Ruiji takeout project - development of business development function Day2
- (翻译)图技术简明历史
- Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
- lotus 1.16.0 延长扇区过期时间
- [CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation
- CDN working principle
- 96. Different binary search trees (medium binary search tree dynamic planning)
猜你喜欢
随机推荐
HCIP(15)
Jmeter 安装第三方插件 Plugins Manager
PaddleNLP基于ERNIR3.0文本分类:WOS数据集为例(层次分类)
SQL injection less42 (post stack injection)
软考网络工程师
Hcip experiment (14)
6K6w5LiA5qyh5pS75Ye75YiG5p6Q
Ngrok intranet penetration
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
20-09-27项目迁移到阿里折腾记录(网卡顺序导致服务无法通过haproxy连接到db)
HCIP(13)
Ruiji takeout - background login function development
基于Ernie-3.0 CAIL2019法研杯要素识别多标签分类任务
npm ERR code ETIMEDOUT npm ERR syscall connect npm ERR errno ETIMEDOUT npm ERR network reques...
Hcip experiment (15)
JMeter installs third-party plug-ins plugins Manager
MOV格式是不是静态图像文件格式
ngx+sql环境离线安装日志(rpm安装)
flask之蓝图 补充openpyxl








