题解 SP27 【SBANK - Sorting Bank Accounts】
STL大法好,来一个map + string吧
其实很简单,每次用6次for循环读入一个string,然后和一个y,每次读入把读入的加到y后面,循环变量大于等于2就加空格!,然后通过map <string, int>类型每次加一,代码如下:
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
map <string, int> mp;
int main()
{
int n, m;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> m;
for(int v = 1; v <= m; v++)
{
string y, p;
for(int j = 1; j <= 6; j++)
{
cin >> p;
if(j >= 2)
{
y += ' ' + p;
}
else
{
y += p;
}
}
mp[y]++;
}
for(map <string, int>::iterator it = mp.begin(); it != mp.end(); ++it)
{
cout << it -> first << " " << it -> second << endl;
}
mp.clear();//这个不能忘
}
return 0;
}
还有另外一个map题解的毒瘤输出是啥?看不懂

浙公网安备 33010602011771号