UVa 10420 List of Conquests (STL map)

Source: Internet
Author: User

10420-list of Conquests

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem &problem=1361

In Act I, Leporello are 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, every size, of every age. (Madamina, IL Catalogoèquesto)

As Leporello records all the ' beauties ' "Don Giovanni ' loved ' in chronological order, it's very troublesome for him to Present his master's conquest to others because him needs to count the number of "' Beauties ' by their nationality each TI Me. You are are to the Leporello to count.

Input

The input consists of at most lines, but. The contains a number n, indicating that there'll be is n more lines. Each following line, with at most characters, contains a country (the word) and the name of a woman (the rest of The words in the line) Giovanni loved. You may assume this name of all countries consist to 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 into that country, Separat Ed by a space.

Sample Input

3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna.

Sample Output

England 1

Spain 2

The nature of skillful use of ++m[c]: When the key is not in the map, a new key-value pair is created.

Complete code:

/*0.016s*/
    
#include <cstdio>  
#include <string>  
#include <map>  
using namespace std ;  
    
Map<string, int> m;  
Map<string, Int>::iterator iter;  
Char str[80], c[80];  
    
int main ()  
{  
    int n;  
    scanf ("%d", &n);  
    while (n--)  
    {  
        scanf ("%s", c);  
        Gets (str);  
        ++M[C];  
    }  
    for (iter = M.begin (); Iter!= m.end (); ++iter)  
        printf ("%s%d\n", (Iter->first). C_str (), iter->second);///use "." will be wrong return  
    0;  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.