想法:
只存國家名稱=>按名稱排序=>找重複數量
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
#include<algorithm> | |
#include<string> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
char a[76]; | |
string b[2001]; | |
scanf("%d",&n); | |
for(int i=0;i<n;i++){ | |
gets(a); | |
cin>>b[i]; | |
} | |
sort(b,b+n); | |
for(int i=0;i<n;){ | |
cout<<b[i]<<' '; | |
int num=1,j; | |
for(j=i+1;j<n;j++){ | |
if(b[i]!=b[j]) break; | |
num++; | |
} | |
printf("%d\n",num); | |
i=j; | |
} | |
return 0; | |
} |
那個get後下面又有Cin是什麼意思 兩個不是都是輸入字串
回覆刪除