記得按照字典順序輸出
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
//string sk;
//getchar();
//getline(cin,sk);
vector < pair <string,int> > v;
for(int i=0;i<t;i++)
{
pair <string,int> p;
string s,s2;
cin>>s;
s2=s;
getline(cin,s);
//cout<<s2<<" /";
bool f=true;
int i2;
for(i2=0;i2<v.size();i2++)
{
if(v[i2].first==s2) {f=0;break;
}
}
if(f||v.empty())p.first=s2,p.second=1,v.push_back(p);
else
{
//cout<<i2<<"i2\n";
v[i2].second++;
}
// cout<<p[i].first<<" "<<p[i].second<<endl;
}
//cout<<endl;
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
cout<<v[i].first<<" "<<v[i].second<<endl;
}
}
AC (20ms, 508KB)