当前位置:网站首页>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;
}边栏推荐
- [disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
- Day11 ---- 我的页面, 用户信息获取修改与频道接口
- 论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
- unittest框架基本使用
- SQL injection for Web Security (1)
- What is the content of game modeling
- Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
- Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively
- 10 smart contract developer tools that miss and lose
- FPGA 学习笔记:Vivado 2019.1 工程创建
猜你喜欢

BOC protected alanine porphyrin compound TAPP ala BOC BOC BOC protected phenylalanine porphyrin compound TAPP Phe BOC Qi Yue supply
![2022-06-30 advanced network engineering (XIV) routing strategy - matching tools [ACL, IP prefix list], policy tools [filter policy]](/img/b6/5d6b946d8001e2d73c2cadbdce72fc.png)
2022-06-30 advanced network engineering (XIV) routing strategy - matching tools [ACL, IP prefix list], policy tools [filter policy]

第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)

第一章: 舍罕王失算
![CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析](/img/70/6fd00146418e5d481e951d51428990.png)
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
![[free sharing] kotalog diary2022 plan electronic manual ledger](/img/ca/1ffbfcc16e3019261f70274a89c16f.jpg)
[free sharing] kotalog diary2022 plan electronic manual ledger

Chapter 20: y= sin (x) /x, rambling coordinate system calculation, y= sin (x) /x with profile graphics, Olympic rings, ball rolling and bouncing, water display, rectangular optimization cutting, R que

01. Preparation for automated office (free guidance, only three steps)

JMeter connection database

第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
随机推荐
Zhang Fei hardware 90 day learning notes - personal record on day 5. Please see my personal profile / homepage for the complete record
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
unittest框架基本使用
Chapitre 1: le roi de shehan a mal calculé
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
WPF format datetime in TextBlock- WPF format DateTime in TextBlock?
Day11 ---- 我的页面, 用户信息获取修改与频道接口
第一章:求n的阶乘n!
Yolov3 network model building
Comments on flowable source code (37) asynchronous job processor
Native table - scroll - merge function
P1891 crazy LCM (Euler function)
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
Win10 share you don't have permission
第一章:三位阶乘和数,图形点扫描
Luogu-p1107 [bjwc2008] Lei Tao's kitten
Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
2020 intermediate financial management (escort class)
交叉编译Opencv带Contrib
BOC protected tryptophan zinc porphyrin (Zn · TAPP Trp BOC) / copper porphyrin (Cu · TAPP Trp BOC) / cobalt porphyrin (cobalt · TAPP Trp BOC) / iron porphyrin (Fe · TAPP Trp BOC) / Qiyue supply