[算法练习] UVA 10420 - List of Conquests?
UVA Online Judge 题目10420 - List of Conquests
问题描述:
题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用)。统计每个国家有多少人参加,按国家名字典排序输出。
输入格式:
第一行是一个整数n,表示参加人数的个数。接下来是n行,每行第一个单词为国家名称,后面为姓名。
输出格式:
每行包括国家名称和出席人数,将国家名称按字典排序输出。
示例输入:
3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna
示例输出:
England 1
Spain 2
代码:(直接用STL吧。。太懒了)
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; struct Country{
string name;
int count = ;
bool operator == (const Country& b) {
return this->name == b.name;
}
}; int cmp(const Country& a, const Country& b){ return a.name < b.name; } vector<Country> Countries;
int main()
{
int n;
char str[];
scanf("%d", &n);
for (int i = ; i < n; i++)
{
scanf("%s", str); //获得国家名
char c;
c = getchar();
while (c != '\n'&&c != EOF){ c = getchar(); } //忽视姓名
Country nowCt;
nowCt.name = str;
vector<Country>::iterator iter = find(Countries.begin(), Countries.end(), nowCt);
if (iter == Countries.end())
{
nowCt.count = ;
Countries.push_back(nowCt);
}
else
{
iter->count++;
}
}
sort(Countries.begin(), Countries.end(), cmp); //排序
for (vector<Country>::iterator it = Countries.begin(); it != Countries.end();it++)
{
cout << it->name << " " << it->count << endl;
}
return ;
}
[算法练习] UVA 10420 - List of Conquests?的更多相关文章
- UVa 10420 List of Conquests
题意就是有N个pl妹子,然后每行第一个单词是妹子的国籍,后面是妹子的名字. 你的任务就是统计相同国籍妹子的个数,然后按字母表顺序输出. 我首先把所有的国籍都读入,然后用qsort()按字母表顺序排序. ...
- RMQ算法 以及UVA 11235 Frequent Values(RMQ)
RMQ算法 简单来说,RMQ算法是给定一组数据,求取区间[l,r]内的最大或最小值. 例如一组任意数据 5 6 8 1 3 11 45 78 59 66 4,求取区间(1,8) 内的最大值.数据量小 ...
- 【KM算法】UVA 11383 Golden Tiger Claw
题目大意 给你一个\(n×n\)的矩阵G,每个位置有一个权,求两个一维数组\(row\)和\(col\),使\(row[i] + col[j]\ge G[i][j]\),并且\(∑row+∑col\) ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)
第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...
- Volume 1. Sorting/Searching(uva)
340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...
- UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
题意: 给出n,求把n写成若干个连续素数之和的方案数. 分析: 这道题非常类似大白书P48的例21,上面详细讲了如何从一个O(n3)的算法优化到O(n2)再到O(nlogn),最后到O(n)的神一般的 ...
- 【UVA 11383】 Golden Tiger Claw (KM算法副产物)
Omi, Raymondo, Clay and Kimiko are on new adventure- in search of new Shen Gong Wu. But EvilBoy Geni ...
- 【set&&sstream||floyed判环算法】【UVa 11549】Calculator Conundrum
CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bored ...
随机推荐
- codeforces 630J Divisibility
J. Divisibility time limit per test 0.5 seconds memory limit per test 64 megabytes input standard in ...
- js获取服务端IP及端口及协议
alert("location:"+window.location); alert("href: "+window.location.href); alert( ...
- oracle 的rowid和rownum
rowid就是唯一标志记录物理位置的一个id,对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行 ...
- 通过OAF实现RTF多语言
职责: Oracle XML Publisher 管理员 -->主页 -->模板 -->创建模板 1.定义rtf模板时 在创建模板时,勾选可转换.
- iOS开发-为程序添加应用设置
一.设置捆绑包 设置捆绑包是应用自带的一组文件,用于告诉设置该应用期望得到用户的哪些偏好设置. 新建设置捆绑包:Command+N,在iOS部分中的Resource,选择Settings Bundle ...
- 关于Ajax使用 Callback 函数
1.onreadystatechange 事件 当请求被发送到服务器时,我们需要执行一些基于响应的任务. 每当 readyState 改变时,就会触发 onreadystatechange 事件. r ...
- 2013年中国区Skyline软件价格体系
< 2013年中国区Skyline软件价格体系 序号 产品名称 描述 市场报价 1 TerraExplorer Pro 5.1 对 ...
- asp.net常用函数
ASP.NET网络编程中常用到的27个函数集 Abs(number) 取得数值的绝对值. Asc(String) 取得字符串表达式的第一个字符ASCII 码. Atn(number) 取得一个 ...
- UNIX基础知识之时间值
本篇博文内容摘自<UNIX环境高级编程>(第二版),仅作个人学习记录所用.关于本书可参考:http://www.apuebook.com/. 长期以来,UNIX系统一直使用两种不同的时间值 ...
- 谷歌chrome浏览器桌面提醒 webkitNotifications
原创: //点击时开启提醒 $(".message_alert").toggle(function(){ $(".message_alert_tip").htm ...