#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i, j, k;
while(cin >> n)
{
string s[n];
string ch;
for(i=0; i<n; i++)
{
cin >> s[i];
getline(cin, ch);
}
sort(s, s+n);
int a[2001] = {0}, c;
string b[2001];
j = 0, i = 0;
while(i<n)
{
string t = s[i];
i++, c = 1;
while(t == s[i])
{
c++;
i++;
}
a[j] = c;
b[j] = t;
j++;
}
for(i=0; i<j-1; i++)
{
for(k=0; k<j-i-1; k++)
{
if(b[k] > b[k+1])
{
swap(a[k], a[k+1]);
swap(b[k], b[k+1]);
}
}
}
for(i=0; i<j; i++)
{
cout << b[i] << " " << a[i] << endl;
}
}
return 0;
}
Comments
Post a Comment