UVA 10420 (暑假-排序、检索 -B - List of Conquests)

来源:互联网 发布:sqlserver增加值 编辑:程序博客网 时间:2024/06/06 01:08
#include <stdio.h>#include <string.h>//#include <algorithm>#include <stdlib.h>using namespace std;int  strcompare(const void *_a, const void *_b){char *a = (char*)_a;char *b = (char*)_b;return strcmp(a, b);}int main() {const int Max = 1050;int n;while (scanf("%d", &n) != EOF) {char str_1[2 * Max][100], str_2[2 * Max][100];getchar();char str[Max];  for (int i = 0; i < n; i++) {memset(str, 0, sizeof(str));gets(str);//保存输入的数据;int len = strlen(str), kong = 0, k = 0;//截取国家名for (int j = 0; j < len; j++) {      if (str[j] >= 'a' && str[j] <= 'z' || str[j] >= 'A' && str[j] <= 'Z')str_1[i][k++] = str[j], kong = 1;else if (kong) {str_1[i][k] = 0;break;}}}//按字母表顺序排序//for (int i = 0; i < n; i++)qsort(str_1, n, sizeof(str_1[0]), strcompare);/*for (int i = 0; i < n - 1; i++) {for (int j = i + 1; j < n; j++) {if (strcmp(str_1[i], str_1[j]) > 0) {char s[100];strcpy(s, str_1[i]);strcpy(str_1[i], str_1[j]);strcpy(str_1[j], s);}}}*///计数并输出int count = 1;for (int i = 0; i < n; i++)if (strcmp(str_1[i], str_1[i+1]) != 0)printf("%s %d\n", str_1[i], count), count = 1;elsecount++;}return 0;}

0 0