UVa10420 List of Conquests
来源:互联网 发布:淘宝矢量图库 编辑:程序博客网 时间:2024/05/25 12:21
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 be nmore 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
Problem-setter:Thomas Tang, Queens University, Canada
“Failure to produce a reasonably good and error freeproblem set illustrates two things a) Lack of creativity b) Lack of commitment”
这题大意就是某个人在不同地方都有许多情人,现要求我们帮其统计他的情人都在哪个国家,及数目。这题只要用字符串读入每行的第一个单词即可,然后以一个数组来存储,同时存下其出现的次数。最后按字典序输出。
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int N = 2100;const int M = 100;char s[N][M];char t[M];int num[N];int cmp(const void *a, const void *b) {return strcmp((char*)a,(char*)b);}int main() {int Case;while (cin >> Case) {memset(num,0,sizeof(num));getchar();for (int i = 0; i < Case; i++) {memset(t,0,sizeof(t));gets(t);for (int j = 0; j < M; j++) {if (t[j] != ' ')s[i][j] = t[j];elsebreak;}}qsort(s,Case,sizeof(s[0]),cmp);int p = 0;num[p]++;for (int i = 1; i < Case; i++) {if (strcmp(s[i],s[i-1]) == 0) {num[p]++;if (i == Case-1)cout << s[i] << " " << num[p] << endl;}else {cout << s[i-1] << " " << num[p] << endl;p++;num[p]++;if (i == Case-1)cout << s[i] << " " << num[p] << endl;}}}return 0;}
- uva10420 - List of Conquests
- UVa10420 List of Conquests
- UVA10420-List of Conquests
- UVA10420 List of Conquests
- UVA10420 - List of Conquests
- 10420 - List of Conquests
- 10420 - List of Conquests
- 10420 - List of Conquests
- uva_10420-List of Conquests
- 10420 - List of Conquests
- 10420 - List of Conquests
- 10420 - List of Conquests
- 10420 - List of Conquests
- List of Conquests
- 10420 - List of Conquests
- uva List of Conquests
- UVa_10420 - List of Conquests
- 10420 - List of Conquests
- FLASH位宽为8、16、32时,CPU与外设之间地址线的连接方法
- MSM8x25 LCD调试分析(一)
- cocos2d游戏开发,常用工具集合
- SQL Sever2008中sa不能登录的解决方法(sa登录失败,错误18456)
- loner_li 机试题 下面是一个由*号组成的4行倒三角形图案。
- UVa10420 List of Conquests
- 苹果终将再次倒下
- HDU,2020,绝对值排序
- cocos2d-x安卓开发环境搭建(windows+eclipse+ndk)
- 廊坊师范学院IT提高班,你真正了解多少?
- spring整合hibernate步骤及配置文件
- mysql 非主键 自动增长
- You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5
- Centos 6.4上配置LAMP