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/