题意就是有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. C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\Team Foundation\4.0\Cache\VersionControl.config is not valid and cannot be loaded.

    Recently, we experienced a strange problem with TFS 2010. We spent a few days before we figured it o ...

  2. HDU 1548 A strange lift (Dijkstra)

    A strange lift http://acm.hdu.edu.cn/showproblem.php?pid=1548 Problem Description There is a strange ...

  3. To Use Ubuntuubunt

    1.rename PC; modify the /etc/hostname. 2.Use root account; 1.set the password for root account: sudo ...

  4. java 静态构造函数

    在java中貌似是没有静态构造函数的. 不过用下面的方式同样可以实现效果. static { }//end 这是静态代码块

  5. EF框架批量更新

    var customers = db.Customers.Where(c => c.name=='小明'); foreach (var customer in customers) { cust ...

  6. ExtJs之Ext.util.ClickRepeater

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  7. 由CAST()函数在.NET1.1和.NET4.0下处理机制不同所引发的BUG

     .NET 1.1版本下使用日期强制转换函数,比如:"select cast(ActionDate as char(7)) as ActionDate  from ST_BookAction ...

  8. SQL Server 中的存储过程

    一:初步了解存储过程的使用 创建一个简单的存储过程 CREATE PROC spEmployee AS SELECT * FROM HumanResources.Employee; 执行这个存储过程: ...

  9. Jmeter之Bean shell使用(二)

    上一篇Jmeter之Bean shell使用(一)简单介绍了下Jmeter中的Bean shell,本文是对上文的一个补充,主要总结下常用的几种场景和方法,相信这些基本可以涵盖大部分的需求.本节内容如 ...

  10. 【hdu1573-X问题】拓展欧几里得-同余方程组

    http://acm.hdu.edu.cn/showproblem.php?pid=1573 求小于等于N的正整数中有多少个X满足: X mod a0 = b0 X mod a1 = b1 …… X  ...