题解 | 句子逆序
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <iostream> #include <string> #include <cstring> #include <vector> #define int long long using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<string> s; string s1; while (cin >> s1) { s.push_back(s1); } int cnt = 0; for (int i = s.size() - 1; i >= 0; i--) { if (cnt == 0) { cout << s[i]; cnt++; } else cout << " " << s[i]; } cout << endl; return 0; } // 64 位输出请用 printf("%lld")
还算是比较简单的题目,开个字符串数组就好了。就是注意再读取的时候,因为空格在读取的时候被忽略了,所以要自己补空格。尤其是作者写这道题的时候很唐,打了双引号,没按空格,在那自我怀疑了好久。#牛客春招刷题训练营#
#牛客春招刷题训练营#