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 ...
随机推荐
- HDOJ 1709 The Balance(母函数)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Nagios 快速实现数据可视化的几种方式
Nagios 是一款强大的开源监控软件,但他本身不能绘图,只能查看当前数据,不能看历史数据以及趋势,也正因此,想要更舒适的使用就要搭配绘图软件,现在可搭配的绘图软件有很多,例如 pnp4nagios, ...
- 高性能javascript及页面注意事项
1.少用全局变量 原因:因为作用域链是一个堆栈的结构,所以遵循先进先出的原则,而javascript引擎在解析代码的时候,将全局对象放在栈底,然后向上依次出现的是不同作用域的活动对象(这些活动对象除了 ...
- ZOJ 2971 Give Me the Number;ZOJ 2311 Inglish-Number Translator (字符处理,防空行,strstr)
ZOJ 2971 Give Me the Number 题目 ZOJ 2311 Inglish-Number Translator 题目 //两者题目差不多,细节有点点不一样,因为不是一起做的,所以处 ...
- Gdata XML解析配置和简单使用
导入libxml2,使用第三方AFNetworking网络请求,第三方XML解析GData GData需要的配置 Build Settings 里搜索,添加如下
- D&F学数据结构系列——二叉排序树
二叉排序树(Binary Sort Tree) 定义:对于树中的每个结点X,它的左子树中所有关键字值小于X的关键字值,而它的右子树中所有关键字值大于X的关键字值. 二叉查找树声明: #ifndef _ ...
- 请问view controller scene,该如何删除
当要删除默认的view controller scene的时候,选中,按del键 注意点击中间的那个左侧按钮,打开scene列表,再选中scene,按del即可删除
- Dev 统计GridControl界面上当前选中的一行的值
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChang ...
- Map中如何把没有定义操作符<的类作为key
Map中如何把没有定义操作符<的类作为key 其实,为了实现快速查找,map内部本身就是按序存储的(比如红黑树).在我们插入<key, value>键值对时,就会按照key的大小顺序 ...
- Linux基础--例行工作
1.仅进行一次的工作排程--at at的工作情况其实是这样的: 1)先找寻/etc/at.allow这个档案,写在这个档案中的使用者才能使用at,没有在这个档案中的使用者则不能使用at(即使没有写在a ...