UVa 10420 List of Conquests

题意就是有N个pl妹子,然后每行第一个单词是妹子的国籍,后面是妹子的名字。

你的任务就是统计相同国籍妹子的个数,然后按字母表顺序输出。

我首先把所有的国籍都读入,然后用qsort()按字母表顺序排序。

List of Conquests
Input: 
standard input
Output: 
standard output
Time Limit: 
2 seconds

In Act I, Leporello is telling Donna Elviraabout his master‘s long list of conquests:

``This is the list of the beauties my master has loved, a list I‘ve madeout myself: take a look, read it with me. In Italy six hundred and forty, inGermany 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 hismaster‘s conquest to others because he needs to count the number of``beauties‘‘ by their nationality each time. You are to help Leporello tocount.

Input

The input consists of at most 2000 lines, but the first. The first linecontains a number n,indicating that there will be n more lines. Each following line, withat most 75 characters, contains a country (thefirst 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 onlyone word.

Output

The output consists of lines in alphabetical order. Eachline starts with the name of a country, followed by the total number of womenGiovanni loved in that country, 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

 

AC代码:

 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7
 8 int main(void)
 9 {
10     #ifdef LOCAL
11         freopen("10420in.txt", "r", stdin);
12     #endif
13
14     int cmp(const void *a, const void *b);
15     int N, i, j;
16     char country[2005][80], c[200];
17     scanf("%d", &N);
18     for(i = 0; i < N; ++i)
19     {
20         scanf("%s", country[i]);
21         gets(c);
22     }
23     qsort(country, N, sizeof(country[0]), cmp);
24
25     i = 0;
26     while(i < N)
27     {
28         j = i;
29         while(strcmp(country[j], country[i]) == 0 && j < N)
30         {
31             ++j;
32         }
33         cout << country[i] << " " << j - i << endl;
34         i = j;
35     }
36     return 0;
37 }
38 int cmp(const void *a, const void *b)
39 {
40     return strcmp((char *)a, (char *)b);
41 }

代码君

UVa 10420 List of Conquests

时间: 2024-08-27 11:55:43

UVa 10420 List of Conquests的相关文章

[算法练习] UVA 10420 - List of Conquests?

UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加,按国家名字典排序输出. 输入格式: 第一行是一个整数n,表示参加人数的个数.接下来是n行,每行第一个单词为国家名称,后面为姓名. 输出格式: 每行包括国家名称和出席人数,将国家名称按字典排序输出. 示例输入: 3Spain Donna ElviraEngland Jane DoeSpain Donn

[2016-01-19][UVA][10420]

时间:2016-01-19  15:16:22  星期二 题目编号:UVA 10420 题目大意:题目 给出 某人, 某个地方 某个爱人,         输出每个地方有几个爱人... 方法:直接对输入数据中的地方进行计数即可, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #inclu

小白书练习题5.5.3 排序检索类、

UVA 340 Master-Mind Hints 题意:猜数字游戏,给n个数的序列给你.接下来一行是答案序列.剩下的都是猜测序列.对于每一个猜测序列,统计有多少个数字相同并且位置相同.有多少数字相同位置不同.每一个数字只能用一次. 思路:直接统计可以求出数字相同并且位置相同的哪一些数.在此过程中我加了一个标记数组.标记那些用过的数的位置为1,没用过为0:然后枚举猜测中哪些没用过的数字.去答案序列中找.当数字相等并且答案行中那个数也没用过时.计数加1: 1 #include<cstdio> 2

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

Volume 1. Elementary Problem Solving :: Sorting/SearchingUva 340,10420,10474,152,299,120,156,400,755

刘汝佳 算法入门 第一版 Uva题目集合(四) Uva 340 #include<stdio.h> #include<string.h> int h[1001][2],g[1001]={0}; int n,m=0,i,j,k,a,b,o; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","

UVA 10420-List of Conquests(STL-map的应用)

List of Conquests Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Problem B List of Conquests Input: standard input Output: standard output Time Limit: 2 seconds In Act I, Leporello is telling Donna El

UVA List of Conquests(字符串按字典排序)

Problem B List of Conquests Input: standard input Output: standard output Time 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

uva 567 - Risk

 Risk  Risk is a board game in which several opposing players attempt to conquer the world. The gameboard consists of a world map broken up into hypothetical countries. During a player's turn, armies stationed in one country are only allowed to attac

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d