我正在编写一个程序,它从文件中读取团队名称并将它们分成组。每个组的大小4.我使用的是:包含在地图中的集合的打印内容
map<int, set<string> > groups
假设团队名称是国家名称。 现在输入所有团队名称进入resp。我想打印每个组的内容,这就是我陷入困境的地方。
这是完整的工作代码,我已经写过。
#include<iostream>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
void form_groups(vector<string>);
int main(){
srand(unsigned(time(NULL)));
string team_name;
vector<string> teams;
while (cin >> team_name)
{
teams.push_back(team_name);
}
random_shuffle(teams.begin(), teams.end());
form_groups(teams);
}
void form_groups(vector<string> teams)
{
map<int, set<string> > groups;
map<int, set<string> >::iterator it;
string curr_item;
int curr_group = 1;
int count = 0;
for(int i = 0; i < teams.size(); i++)
{
curr_item = teams.at(i);
count++;
if(count == 4)
{
curr_group += 1;
count = 0;
}
groups[curr_group].insert(curr_item);
}
cout << curr_group << endl;
for(it = groups.begin(); it != groups.end(); ++it)
{
}
}
是它最后的'for'循环,迭代过''groups'你map'不确定? – hmjd 2012-07-08 09:14:28
是的,我想打印内容,我不知道该怎么做。 – R11G 2012-07-08 13:50:09