[算法练习] 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 ...
随机推荐
- Session,Cookie 和local storage的区别
以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...
- java 2 8 10 16
An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or ...
- <%%>与<scriptrunat=server>,<%=%>与<%#%>的区别
这些东西都是asp.net前台页面与后台代码交互过程中经常使用的,它们之间有的非常相似,又有一些不同.对比学习下,看看他们之间的联系与区别. 首先看<%%>与<scriptrun ...
- servlet--页面自刷新
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...
- Python3爬虫学习
学了几天python3,发现目前学到的与爬虫还是关系不大,所以现在准备爬虫和语言同步学习. 2016.8.9晚 先从最简单的开始,爬取指定url的所有内容: #encoding:UTF-8 impor ...
- 解决mysql导入导出数据乱码问题
最近在linux上面用mysqldump导出数据,放在windows系统中导入就会出现中文乱码,然后就会导致出现: Unknown MySQL server host和Can't connect to ...
- 通过克隆MAC地址 破解网通电信封路由
通过克隆MAC地址 破解网通电信封路由 电信封路由方法一:先确定申请上网的电脑单机状态下已经能够上网.就说明该电脑网卡的MAC地址是合法的MAC地址.进入系统的MSDOS方式,发布ipconfig/a ...
- MEF 编程指南(十二):批量组合
MEF 容器实例并非不可变的.如果目录支持改变(像监控目录变动)或者在运行时添加/移除部件都可能发生改变.以前,你不得不做出改动并且调用 CompositionContainer 上的 Compose ...
- VMware虚拟机扩容
作者:金良(golden1314521@gmail.com) csdn博客:http://blog.csdn.net/u012176591 用了一段Linux虚拟机.发现安装虚拟机时分配的空间不够用, ...
- delphi 修改Hint的字体和颜色
//修改Hint的字体和颜色 public { Public declarations } procedure Sshowhint(var hintstr:string;var can ...