当前位置:网站首页>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;
}
边栏推荐
- HCIP(9)
- Lotus 1.16.0 extend sector expiration time
- MySQL built-in functions
- Hcip experiment (14)
- 微信小程序里button点击的时候会边框有黑线
- [LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
- 105. Construct binary tree from preorder and inorder traversal sequence (medium binary tree DFS hash table binary tree)
- HCIP(13)
- 软考网络工程师
- elment-plus图标input上面带的图标为什么不显示
猜你喜欢
HCIP(14)
静态路由和缺省路由实验
Win11怎么打开软件通知
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
SQL injection less34 (post wide byte injection + Boolean blind injection)
What is time complexity
MySQL built-in functions
The blueprint of flask complements openpyxl
Att & CK preliminary understanding
79. Word search (medium string array matrix backtracking)
随机推荐
Leetcode integer exercises integer inversion
ECMASript 5/6 笔记
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
redis相关
[leetcode] maximum depth of binary tree
Static details of static members
Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
Alibaba cloud CDN practice
网易云信 2022Q2 产品补给站,快来获取你的产品补给计划吧!
TensorFlow Serving 高性能的机器学习模型服务系统
Sword finger offer II 057. the difference between the value and the subscript is within the given range (medium array bucket sort sliding window TreeSet)
How to install WiFi correctly
Ecmasript 5/6 notes
mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题
Ruiji takeout - background login function development
Sword finger offer II 066. sum of words (medium prefix tree design string)
ATT&CK初步了解
SQL injection less42 (post stack injection)
删除容器镜像报错解决image is referenced in multiple repositories
Log4j vulnerability elk platform processing method (logstah5.5.1)