当前位置:网站首页>Pat grade B 1009 is ironic (20 points)
Pat grade B 1009 is ironic (20 points)
2022-07-03 19:39:00 【How far is it forever】
Give me an English sentence , Ask you to write a program , Reverse the order of all the words in the sentence .
Input format :
The test input contains a test case , The total length given in one line does not exceed 80 String . A string consists of several words and spaces , The words are made of English letters ( There is a distinction between case and case ) Composed string , Use... Between words 1 Separate the spaces , Type to make sure there are no extra spaces at the end of the sentence .
Output format :
The output of each test case takes up one line , Output the sentences in reverse order .
Examples :"> sample input :
Hello World Here I Come
sample output :
Come I Here World HelloMethod 1 ( Refer to Qingshen code )
because PAT It's a single point test , Therefore, this more concise method is produced , The box EOF To determine whether the word has been entered
It should be noted that when entering manually, press ctrl + z End procedure
#include <iostream>
using namespace std;
int main()
{
int num = 0;
char ans[90][90];
while (scanf("%s", ans[num]) != EOF) {
num++;
}
for (int i = num - 1; i >= 0; i--) {
printf("%s", ans[i]);
if (i > 0) cout << " ";
}
return 0;
}Method 2 simulation
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
getline(cin, s);
char ans[90][90];
int r = 0, h = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != ' ') {
ans[r][h++] = s[i];
}
else {
r++; h = 0;
}
}
for (int i = r; i >= 0; i--) {
cout << ans[i];
if (i != 0) cout << " ";
}
return 0;
}#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string s, temp = "";
getline(cin, s);
vector<string> ans;
for (int i = 0; i < s.size(); i++) {
if (s[i] != ' ') temp += s[i];
else {
ans.push_back(temp);
temp = "";
}
}
ans.push_back(temp);
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i];
if (i != 0) cout << " ";
}
return 0;
}Method 3 Use c++ Medium istringstream
istringstream Class to execute C++ Style stream input operation
istringstream The original form of the constructor is as follows :
istringstream::istringstream(string str), Its function is from string object str Read characters in
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string s, word;
getline(cin, s);
vector<string>ans;
istringstream ss(s);
while (ss >> word) {
ans.push_back(word);
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i];
if (i != 0) cout << " ";
}
return 0;
}边栏推荐
- Xctf attack and defense world crypto master advanced area olddriver
- 第一章:递归求n的阶乘n!
- This Chinese numpy quick look-up table is too easy!
- 第一章:拓广同码小数和s(d, n)
- Ae/pr/fcpx super visual effects plug-in package fxfactory
- QT -- qfile file read / write operation
- Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
- The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
- UE source code analysis: uccharactermovementcomponent - rootmotion
- 论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
猜你喜欢

Recommend a GIF processing artifact less than 300K - gifsicle (free download)

The earliest record
![2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]](/img/b6/5d6b946d8001e2d73c2cadbdce72fc.png)
2022 - 06 - 30 networker Advanced (XIV) Routing Policy Matching Tool [ACL, IP prefix list] and policy tool [Filter Policy]

PR 2021 quick start tutorial, how to create a new sequence and set parameters?

QT -- qfileinfo file information reading

2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)

Basic principle of LSM tree

05 -- QT OpenGL draw cube uniform

The necessity of lean production and management in sheet metal industry

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
随机推荐
BUUCTF
Think of new ways
Professional interpretation | how to become an SQL developer
Free sharing | linefriends hand account inner page | horizontal grid | not for sale
The most valuable thing
Zhang Fei hardware 90 day learning notes - personal records on day 4, please see my personal profile / homepage for the complete
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
If the warehouse management communication is not in place, what problems will occur?
PR FAQ: how to set PR vertical screen sequence?
Day10 ---- 强制登录, token刷新与jwt禁用
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
JMeter connection database
Titles can only be retrieved in PHP via curl - header only retrieval in PHP via curl
Web Security (VII) specific process of authentication with session cookie scheme
Floating source code comment (38) parallel job processor
P3402 persistent and searchable
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue
Phpstudy set LAN access
Chapter 1: find the factorial n of n!