题目:
解答:
这道题不难,但是如何优雅的拼是个问题,解答中的做法实在是无奈之举
int main()
{
int aim;
int num;
cin >> aim;
cin >> num;
vector<vector<int>> res;
int max = 0;
while (num--)
{
string str;
cin >> str;
vector<int> tmp = str2vint(str, ',');
max = tmp.size() > max ? tmp.size() : max;
res.push_back(tmp);
}
vector<int> rest;
int usednum = 0;
int cnt = 0;
while (cnt * aim < max)
{
for (int i = 0; i < res.size(); i++)
{
for (int j = aim*cnt; j < (aim * cnt+ aim) &&j < res[i].size(); j++)
{
rest.push_back(res[i][j]);
}
}
cnt++;
}
int comm = 0;
for (auto it : rest)
{
if (comm == 1)
{
cout << ',';
}
cout << it;
comm = 1;
}
return 0;
}