我正在編寫一個程序,它從文件中讀取團隊名稱並將它們分成組。每個組的大小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