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代码:
- //#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的更多相关文章
- [算法练习] UVA 10420 - List of Conquests?
UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. Sorting/Searching(uva)
340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)
第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
随机推荐
- 新浪SAE中文分词接口
最近发现新浪SAE平台上竟然也提供分词功能,分词效果也还不错,由新浪爱问提供的分词服务,研究了一番,做了一个简易版的在线调用接口(get方式,非post) 官网说明:http://apidoc.sin ...
- Java 8怎么了之二:函数和原语
[编者按]本文作者为专注于自然语言处理多年的 Pierre-Yves Saumont,Pierre-Yves 著有30多本主讲 Java 软件开发的书籍,自2008开始供职于 Alcatel-Luce ...
- MVC中 ViewBag、ViewData和TempData区别
MVC3中 ViewBag.ViewData和TempData的使用和区别 public dynamic ViewBag { get; } public ViewDataDictionary View ...
- PC端模拟手机浏览网页
很多网站都通过User-Agent来判断浏览器类型,如果是3G手机,显示手机页面内容,如果是普通浏览器,显示普通网页内容. 谷歌Chrome浏览器,可以很方便地用来当3G手机模拟器.在Windows的 ...
- 理解Flight框架核心
http://blog.csdn.net/sky_zhe/article/details/38906689 Flight 框架 Flight类 1.加载 autoload.php ,启动框架的自动加载 ...
- URAL 1586 Threeprime Numbers(DP)
题目链接 题意 : 定义Threeprime为它的任意连续3位上的数字,都构成一个3位的质数. 求对于一个n位数,存在多少个Threeprime数. 思路 : 记录[100, 999]范围内所有素数( ...
- SQL Server 基础 之 GROUP BY子句
GROUP BY 子句用于聚合信息 先看个实例,没有使用 GROUP BY 子句 SELECT SalesOrderID,OrderQty FROM Sales.SalesOrderDetail WH ...
- Log4net学习
转自:http://www.cnblogs.com/sirkevin/archive/2012/06/13/2548449.html Log4net简介根据日志类别保存到不同的文件,并按照日期生成不同 ...
- Task 使用 Task以及Task.Factory都是在.Net 4引用的。Task跟Thread很类似,通过下面例子可以看到。
static public void ThreadMain() { Thread t1 = new Thread(TaskWorker); t1.Start(3); } static public v ...
- Project Euler 108:Diophantine reciprocals I 丢番图倒数I
Diophantine reciprocals I In the following equation x, y, and n are positive integers. For n = 4 the ...