UVA10420-List of Conquests

思路:只需比较前面国家的名称就行了,记得要排序完再进行下一步操作,这样比较方便!!!!!

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

char cname[2005][80];
char pname[2005][80];

int compare(const void *a, const void *b){
	return strcmp((char *)a, (char *)b);
}

int main(){
	int n;
	scanf("%d", &n);	
	for(int i = 0; i < n; i++){		
		scanf("%s", cname[i]);	
		gets(pname[i]);	
					
	}
	qsort(cname, n, sizeof(char)*80, compare);		
	int tmp = 1;	
	for(int i = 1; i <= n; i++){	
		if (strcmp(cname[i], cname[i - 1]) == 0 && i < n)	
			tmp++;	
		else{
			printf("%s %d\n", cname[i - 1], tmp);	
			tmp = 1;	
		}	
	}
	return 0;
}



你可能感兴趣的:(UVA10420-List of Conquests)