题解 | 单词倒排
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream> #include <string> #include <vector> #define int long long using namespace std; signed main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<string> s(10000); char c; int i = 0; while (cin.get(c) && c != '\n') { if (c < 'A' || c > 'Z' && c < 'a' || c > 'z') { i++; s[i] = " "; i ++; continue; } if (c == ' ') { i++; s[i] = " "; i++; continue; } s[i] = s[i] + c; } for (int j = i; j >= 0; j--) { cout << s[j]; } cout << endl; return 0; } // 64 位输出请用 printf("%lld")
这道题还是写的很纯,不知道有没有什么简单的方法。最近脑子不太好用,需要换个脑子哩()。还有,用vector如果想直接访问读入的话,就要开大点,不然真的会报段错误,别问我怎么知道的。#牛客春招刷题训练营#
#牛客春招刷题训练营#