UVA 10420-List of Conquests(STL-map的应用)

List of Conquests

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

Problem B

List of Conquests

Input: standard input

Output: standard output

Time Limit: 2 seconds

In Act I, Leporello is telling Donna Elvira about his master‘s long list of conquests:

``This is the list of the beauties my master has loved, a list I‘ve made out myself: take a look, read it with me. In Italy six hundred and forty, in Germany 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 his master‘s conquest to others because he needs to count the number of ``beauties‘‘ by their nationality
each time. You are to help Leporello to count.

Input

The input consists of at most 2000 lines, but the first. The first line contains a number n, indicating that there will be n more lines. Each following line, with at most 75 characters,
contains a country (the first 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 only one word.

Output

The output consists of lines in alphabetical order. Each line starts with the name of a country, followed by the total number of women Giovanni 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

题意:一个富豪在n个地方有情妇,第一个单词是国家,后面跟着的是人名。问每个国家里面情妇的人数。

小技巧:当用scanf输入字符串的时候不能包含空格,gets输入字符串的时候可以包含空格。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int main()
{
    int n;
    char country[110];
    char woman[110];
    map<string,int >G;
    map<string,int >::iterator it;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%s",country);
        gets(woman);
        G[country]++;
    }
    for(it=G.begin();it!=G.end();it++)
    {
        cout<<it->first<<' '<<it->second<<endl;
    }
    return 0;
}
时间: 2024-10-15 12:16:49

UVA 10420-List of Conquests(STL-map的应用)的相关文章

[算法练习] UVA 10420 - List of Conquests?

UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加,按国家名字典排序输出. 输入格式: 第一行是一个整数n,表示参加人数的个数.接下来是n行,每行第一个单词为国家名称,后面为姓名. 输出格式: 每行包括国家名称和出席人数,将国家名称按字典排序输出. 示例输入: 3Spain Donna ElviraEngland Jane DoeSpain Donn

UVa 10420 List of Conquests

题意就是有N个pl妹子,然后每行第一个单词是妹子的国籍,后面是妹子的名字. 你的任务就是统计相同国籍妹子的个数,然后按字母表顺序输出. 我首先把所有的国籍都读入,然后用qsort()按字母表顺序排序. List of ConquestsInput: standard inputOutput: standard outputTime Limit: 2 seconds In Act I, Leporello is telling Donna Elviraabout his master's long

UVA 12096 STL map set 的使用

set这个容器也是STL库的一员,并且在algorithm内直接有 set_union set_intersection  这样求并集交集的操作 map 最方便的地方就是 支持下标访问 举例说明 : 1 #include<iostream> 2 include<cstdio> 3 #include<cstring> 4 #include<vector> 5 #include<map> 6 #include<set> 7 #includ

uva 12096 - The SetStack Computer(STL)

UVA 12096 - The SetStack Computer 题目链接 题意:几个操作,push是在栈顶加入一个空集,dup是复制栈顶集合,在放入栈顶,union是把头两个取并集放回,int是头两个取交集放回,add是取头两个,把第一个当成一个集合加入第二个,每次操作输出栈顶集合的里面的个数 思路:用set,stack模拟,然后利用map去hash一个集合,模拟即可 代码: #include <cstdio> #include <cstring> #include <s

[2016-01-19][UVA][10420]

时间:2016-01-19  15:16:22  星期二 题目编号:UVA 10420 题目大意:题目 给出 某人, 某个地方 某个爱人,         输出每个地方有几个爱人... 方法:直接对输入数据中的地方进行计数即可, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #inclu

stl::map之const函数访问

如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const { if (_map_name_value.find(name) != _map_name_value.end()) { return _map_name_value[name]; } return ""; } 上面的代码会报错:error C2678: 二进制“[”: 没有找到接受“c

hdu 4941 Magical Forest(STL map &amp; 结构体运用)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 220    Accepted Submission(s): 105 Problem Description There is a forest c

(转载)STL map与Boost unordered_map的比较

原链接:传送门 今天看到 boost::unordered_map,它与 stl::map的区别就是,stl::map是按照operator<比较判断元素是否相同,以及比较元素的大小,然后选择合适的位置插入到树中.所以,如果对map进行遍历(中序遍历)的话,输出的结果是有序的.顺序就是按照operator< 定义的大小排序.而boost::unordered_map是计算元素的Hash值,根据Hash值判断元素是否相同.所以,对unordered_map进行遍历,结果是无序的. 用法的区别就是

ZOJ1109_Language of FatMouse(STL/map)

解题报告 题意: 略. 思路: map应用. #include <algorithm> #include <iostream> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <map> using namespace std; map<string,stri

POJ训练计划3096_Surprising Strings(STL/map)

解题报告 题目传送门 题意: 给一个字符串,要求,对于这个字符串空隔为k取字符对(k=0,1,2,3,4...)要求在相同的空隔取对过程汇总,整个字符串中没有一个相同字符对如: ZGBZ: 间隔为0的字符对有: ZG.GB.BZ,三个均不相同 间隔为1的字符对有: ZG. GZ,均不相同 间隔为2的字符对有: ZZ 仅有一个,不必比较. 这种字符串定义为"surprising". 之后按照格式输出. 思路: map暴力. #include <iostream> #inclu