#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; } }这个可以吗?
点赞 评论

相关推荐

就只能3个月,但是要求长期全职实习
Swaying:你确实是能长期实习啊,但是你那时候有事也没啥办法嘛
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
06-11 15:52
东南大学 C++
问了一下hr,这个回答是G了吗
椛鸣:我遇到过 我给你翻一下 对不起 我之前把你当备胎了 现在我人已经招满了 ***吧
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务