#include <iostream> #include <vector> #include <string> #include <set> #include <map> #include <deque> #include <algorithm> using namespace std; deque<char> str2vec(string s){ deque<char> res; for (char c : s){ if (c !=','){ res.push_back(c); } } return res; } string vec2str(vector<char> s){ string res = ""; for (int i = 0; i < s.size(); i++){ if (i == s.size()-1) res+= s[i]; else res = res + s[i] + ','; } return res; } vector<char> process(vector<deque<char>> stringarr, int sum, string k){ vector<char> res; int i = 0; // 用以说明遍历到了第几组数 int cnt = 0; int num = atoi(k.c_str()); while (cnt < sum) { int j = 0; while(j++ < num) { if (stringarr[i].empty()) break; res.push_back(stringarr[i].front()); stringarr[i].pop_front(); cnt++; } i++; if (i >= stringarr.size()) i=0; } return res; } int main(){ while (1){ string k; string s; int sum = 0; bool flag = true; string ans; vector<deque<char>> stringarr; while (getline(cin, s)){ if (flag){ k = s; flag = false; continue; } if (s.empty()) break; deque<char> qs = str2vec(s); stringarr.push_back(qs); } for (auto i : stringarr) sum += i.size(); vector<char> res = process(stringarr, sum ,k); ans = vec2str(res); cout <<ans<<endl; } }这个可以吗?
点赞 评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务