题意就是有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代码:

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int main(void)
{
#ifdef LOCAL
freopen("10420in.txt", "r", stdin);
#endif int cmp(const void *a, const void *b);
int N, i, j;
char country[][], c[];
scanf("%d", &N);
for(i = ; i < N; ++i)
{
scanf("%s", country[i]);
gets(c);
}
qsort(country, N, sizeof(country[]), cmp); i = ;
while(i < N)
{
j = i;
while(strcmp(country[j], country[i]) == && j < N)
{
++j;
}
cout << country[i] << " " << j - i << endl;
i = j;
}
return ;
}
int cmp(const void *a, const void *b)
{
return strcmp((char *)a, (char *)b);
}

代码君

UVa 10420 List of Conquests的更多相关文章

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

    UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. Volume 1. Sorting/Searching(uva)

    340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...

  4. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)

    第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. JavaScript 文件上传类型判断

    文件上传时用到一个功能,使用html元素的input标签实现, <input id="imageFile" name="imageFile1" accep ...

  2. HDOJ 1226 超级密码

    超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. Form的用法

    提交页面: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  4. myeclipse 10的破解以及运行run.bat错误或者双击立即消失的问题

    安装包下载: ed2k://|file|[myeclipse.10.0.更新发布].myeclipse-10.0-offline-installer-windows.exe|947752488|73b ...

  5. MJRefresh插件引起的错误

    添加的头部或者尾部刷新,离开这个界面的时候需要移除 - (void)dealloc {    [_tableView removeHeader];} 不同版本的处理的方式不同 报的错误: 类的一个实例 ...

  6. POJ 1496

    #include <iostream> #include <string> using namespace std; int fac(int num); int C(int n ...

  7. FastReport报表

    http://www.fastreportcn.com/product/FASTREPORT_dotNET.html

  8. PHP 判断是否包含某字符串

    PHP语言是一个功能强大的嵌入式HTML脚本语言,它的易用性让许多程序员选择使用.PHP判断字符串的包含,可以使用PHP的内置函数 strstr,strpos,stristr直接进行判断.也可以通过e ...

  9. poj 2311 Cutting Game 博弈论

    思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<c ...

  10. 【poj1284-Primitive Roots】欧拉函数-奇素数的原根个数

    http://poj.org/problem?id=1284 题意:给定一个奇素数p,求p的原根个数. 原根: { (xi mod p) | 1 <= i <= p-1 } is equa ...