Uva10420-List of conquests

Source: Internet
Author: User
Tags strcmp

 

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 ''beauty'' by their nationality each time. you are
To help Leporello to count.

Input

The input consists of at most2000Lines, but the first. The first line contains a number
N, Indicating that there will beNMore lines. Each following line, with at most
75Characters, 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

At first, I didn't see the name of the person who thought there could be duplicates. Simply sort individual keywords by country without sorting by number of people and then sort by country.

# Include <stdio. h>
# Include <string. h>
Char country [2000] [100];
Int sum = 0;
Void sort (int l, int R, int A [])
{Int I = L, j = r, x = A [I], II;
Char ch [100];
Strcpy (CH, country [I]);
If (L> = r) return;
While (I <j)
{While (I <J & (strcmp (country [J], CH)> 0) -- J;
Strcpy (country [I], country [J]); A [I] = A [J];
While (I <J & (strcmp (country [I], CH) <0) ++ I;
Strcpy (country [J], country [I]); A [J] = A [I];
}
A [I] = x; strcpy (country [I], CH );
Sort (L, I-1, );
Sort (I + 1, R, );
};
Void main ()
{Char s [1, 100], S1 [2, 100];
Int T, num [2000], I, j, F;
Scanf ("% d \ n", & T );
While (t --)
{Scanf ("% s", & S );
Gets (S1 );
F = 1;
For (I = 0; I <sum; I ++)
If (strcmp (country [I], S) = 0)
{++ Num [I];
F = 0;
}
If (f)
{Num [Sum] = 1;
Strcpy (country [Sum], S );
++ Sum;
}
}
Sort (0, Sum-1, num );
For (I = 0; I <sum; I ++)
Printf ("% S % d \ n", country [I], num [I]);
}

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.