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?的更多相关文章

  1. UVa 10420 List of Conquests

    题意就是有N个pl妹子,然后每行第一个单词是妹子的国籍,后面是妹子的名字. 你的任务就是统计相同国籍妹子的个数,然后按字母表顺序输出. 我首先把所有的国籍都读入,然后用qsort()按字母表顺序排序. ...

  2. RMQ算法 以及UVA 11235 Frequent Values(RMQ)

    RMQ算法 简单来说,RMQ算法是给定一组数据,求取区间[l,r]内的最大或最小值. 例如一组任意数据 5 6 8 1 3 11 45 78 59 66 4,求取区间(1,8)  内的最大值.数据量小 ...

  3. 【KM算法】UVA 11383 Golden Tiger Claw

    题目大意 给你一个\(n×n\)的矩阵G,每个位置有一个权,求两个一维数组\(row\)和\(col\),使\(row[i] + col[j]\ge G[i][j]\),并且\(∑row+∑col\) ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)

    第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...

  6. Volume 1. Sorting/Searching(uva)

    340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...

  7. UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers

    题意: 给出n,求把n写成若干个连续素数之和的方案数. 分析: 这道题非常类似大白书P48的例21,上面详细讲了如何从一个O(n3)的算法优化到O(n2)再到O(nlogn),最后到O(n)的神一般的 ...

  8. 【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 ...

  9. 【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 ...

随机推荐

  1. MSXML读取XML中文

    // QueryNodes.cpp : Defines the entry point for the console application. // #include <stdio.h> ...

  2. Codeforces Round #362 (Div. 2) C. Lorenzo Von Matterhorn (类似LCA)

    题目链接:http://codeforces.com/problemset/problem/697/D 给你一个有规则的二叉树,大概有1e18个点. 有两种操作:1操作是将u到v上的路径加上w,2操作 ...

  3. DllImport属性详解

    API函数是构筑Windows的基石, 是Windows编程的必备利器.每一种Windows应用程序开发工具都提供间接或者直接的方式调用Win32API,C#也不例外.使用Win32API的一个好处就 ...

  4. 用C++ 自娱自乐

    最无聊的时光当属 考试前的复习时段了,在一些论坛上看到一些用字符组成的图像,觉得有点意思,于是,自己 用C++ 参考一些论坛的图像,写了下面这个东西,来表达此时的心情. #include<ios ...

  5. window.showModalDialog基础

    本文转载:http://www.cnblogs.com/sunnycoder/archive/2010/05/05/1728047.html 基本知识 l  showModalDialog() (IE ...

  6. SQL拆分多规则的字符串分离数字。

    --拆分多规则字符串 DECLARE @Codes NVARCHAR(MAX) SET @Codes = '6*BC-007,*BC-016,9*BC-015' --对于*BC-015这种情况,则Qt ...

  7. InfluxDB安装

    参考https://www.influxdata.com/downloads/#influxdb 官网 OS X brew update brew install influxdb Docker Im ...

  8. OpenStack Magnum 项目简单介绍

    背景 Magnum 项目是 2014 年 11 月增加 OpenStack 的年轻项目,由 Rackspace主导发起,其定位是提供容器即服务(Container as a Service)的 API ...

  9. lucene_indexWriter说明、索引库优化

    IndexWriter Hibernate的SessionFactory 在Hibernate中.一般保持一个数据库就仅仅有一个SessionFactory.由于在SessionFactory中维护二 ...

  10. C语言面试题大汇总

    static有什么用途?(请至少说明两种)1.限制变量的作用域2.设置变量的存储域7. 引用与指针有什么差别?1) 引用必须被初始化,指针不必.2) 引用初始化以后不能被改变,指针能够改变所指的对象. ...