UVA 10420 (13.07.27)
来源:互联网 发布:易语言挂机锁源码 编辑:程序博客网 时间:2024/06/05 02:39
Problem B
List of Conquests
Input:standardinput
Output: standard output
Time Limit: 2 seconds
In Act I, Leporello is tellingDonna 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 hundredand 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 arecountry 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)
AsLeporello records all the ``beauties'' Don Giovanni ``loved'' in chronological order,it is very troublesome for him to present his master's conquest to othersbecause he needs to count the number of ``beauties'' by their nationality eachtime. You are to help Leporello to count.
Input
Theinput consists of at most 2000lines, but the first. The first line contains a numbern, indicating that there will benmore lines. Each following line, with at most75 characters, contains a country (the first word) and the name ofa woman (the rest of the words in the line) Giovanni loved. You may assume thatthe name of all countries consist of only one word.
Output
Theoutput consists of lines in alphabetical order. Each line starts with the nameof a country, followed by the total number of women Giovanni loved in thatcountry, separated by a space.
Sample Input
3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna
Sample Output
England 1
Spain 2
题意:我说的直白点, 一个男的, 喜欢世界各国的美女
现在他给出清单, 每一行的第一个单词是国别, 后面是在该国他喜欢的女人的名字
我们要做的就是帮他统计, 每个国家有多少个他喜欢的女人~
注意: 输出是按字典序的
(这题UVA的数据也很水, 理论上要是某两行的国家和人名是相同的, 就算一个, 但是我的代码没考虑到这个问题, 居然A了)
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct country {char name[80];int num;};country date[2008];int cmp(const void *a, const void *b) {return strcmp((*(country *)a).name, (*(country *)b).name);}int main() {int T;int len;char str[80];char t_name[80];char ch;int count = 0;scanf("%d%c", &T, &ch);for(int i = 0; i < T; i++) {gets(str);len = strlen(str);for(int j = 0 ; j < len; j++) {if(str[j] != ' ')t_name[j] = str[j];else {t_name[j] = '\0';break;}}int mark = 1;for(int j = 0 ; j < count; j++) {if(strcmp(t_name, date[j].name) == 0) {date[j].num++;mark = 0;break;}}if(mark) {strcpy(date[count].name, t_name);date[count].num = 1;count++;}}qsort(date, count, sizeof(date[0]), cmp);for(int i = 0; i < count; i++)printf("%s %d\n", date[i].name, date[i].num);return 0;}
- UVA 10420 (13.07.27)
- UVA 340 (13.07.27)
- uva 10420
- uva 10420
- uva 10420
- uva-10420
- uva 10420
- uva 10420
- uva 10420
- UVA 539 (13.07.08)
- UVA 133 (13.07.07)
- UVA 10004 (13.07.09)
- UVA 10596 (13.07.11)
- UVA 10054 (13.07.11)
- UVA 10252 (13.07.13)
- UVA 10167 (13.07.17)
- UVA 11292 (13.07.17)
- UVA 113 (13.07.17)
- PP业务表
- 【黑马程序员】Queue队列
- UVa:10954 Add All
- java 内部类的作用
- linux中断处理------顶半部与底半部
- UVA 10420 (13.07.27)
- lightoj 1008
- 关于PHP的unset:
- 【黑马程序员】正则表达式
- 需求梳理工作坊
- 【黑马程序员】接收键盘输入
- Linux下删除文件夹
- 时间转换
- POJ 分类(来自网上)