List of Conquests(排序水题)

Uva 10420 – List of Conquests(排序水题)

Problem BList of ConquestsInput:standard input Output:standard outputTime Limit:2 seconds

In Act I, Leporello is telling Donna Elvira about his master’s long list of conquests:

“This is the list of the beauties my master has loved, a list I’ve made out myself: take a look, read it with me. In Italy six hundred and forty, in Germany two hundred and thirty-one, a hundred in France, ninety-one in Turkey; but in Spain already a thousand and three! Among them are country girls, waiting-maids, city beauties; there are countesses, baronesses, marchionesses, princesses: women of every rank, of every size, of every age.” (Madamina, il catalogo è questo)

As Leporello records all the “beauties” Don Giovanni “loved” in chronological order, it is very troublesome for him to present his master’s conquest to others because he needs to count the number of “beauties” by their nationality each time. You are to help Leporello to count.

Input

The input consists of at most2000lines, but the first. The first line contains a numbern, indicating that there will benmore lines. Each following line, with at most75characters, contains a country (the first word) and the name of a woman (the rest of the words in the line) Giovanni loved. You may assume that the name of all countries consist of only one word.

Output

The output consists of lines in alphabetical order. Each line starts with the name of a country, followed by the total number of women Giovanni loved in that country, separated by a space.

Sample Input3Spain Donna ElviraEngland Jane DoeSpain Donna AnnaSample OutputEngland 1

Spain 2

Problem-setter:Thomas Tang, Queens University, Canada

“Failure to produce a reasonably good and error free problem set illustrates two things a) Lack of creativity b) Lack of commitment”

#include<stdio.h>#include<string.h>typedef struct{char name[75];int sum;}beaut;beaut country[2010];int main(){int i, j, t, n, flag, temp, cnt = 0;char input[80], name[75];for(i=0; i<2010; ++i){memset(country[i].name, , sizeof(char)*75);country[i].sum = 0;}scanf(, &n);getchar();for(t=1; t<=n; ++t){fgets(input, 80, stdin);sscanf(input, , name);if(cnt == 0){strcpy(country[cnt].name, name);country[cnt++].sum++;}else{for(i=0; i<cnt && strcmp(country[i].name, name); ++i);if(i >= cnt){strcpy(country[cnt].name, name);country[cnt++].sum++;}else country[i].sum++;}}for(i=0; i<cnt-1; i++){flag = 0;for(j=0; j<cnt-1-i; ++j){if(strcmp(country[j].name, country[j+1].name) > 0){flag = 1;memset(name, , sizeof(name));strcpy(name, country[j].name);strcpy(country[j].name, country[j+1].name);strcpy(country[j+1].name, name);temp = country[j].sum;country[j].sum = country[j+1].sum;country[j+1].sum = temp;}}if(!flag) break;}for(i=0; i<cnt; ++i)printf(, country[i].name, country[i].sum);return 0;}

解题报告:

因为没看清题目,贡献了一次WA!

posted on

,虚拟主机,美国空间,美国服务器最好的节约是珍惜时间,最大的浪费是虚度年华。

List of Conquests(排序水题)

相关文章:

你感兴趣的文章:

标签云: