Sicily 1447. Open Source

来源:互联网 发布:三步倒淘宝叫什么暗号 编辑:程序博客网 时间:2024/06/06 03:21

1447. Open Source

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

At an open-source fair held at a major university, leaders of open-source projects put sign-up sheets on the wall, with the project name at the top in capital letters for identification.

Students then signed up for projects using their userids. A userid is a string of lower-case letters and numbers starting with a letter.

The organizer then took all the sheets off the wall and typed in the information.

Your job is to summarize the number of students who have signed up for each project. Some students were overly enthusiastic and put their name down several times for the same project. That's okay, but they should only count once. Students were asked to commit to a single project, so any student who has signed up for more than one project should not count for any project.

There are at most 10,000 students at the university, and at most 100 projects were advertised.

Input

The input contains several test cases, each one ending with a line that starts with the digit 1. The last test case is followed by a line starting with the digit 0.

Each test case consists of one or more project sheets. A project sheet consists of a line containing the project name in capital letters, followed by the userids of students, one per line.

Output

For each test case, output a summary of each project sheet. The summary is one line with the name of the project followed by the number of students who signed up. These lines should be printed in decreasing order of number of signups. If two or more projects have the same number of signups, they should be listed in alphabetical order.

Sample Input

UBQTS TXTtthumbLIVESPACE BLOGJAMphiltonaeinsteinYOUBOOKj97leesswxyzyj97leeaeinsteinSKINUX10

Sample Output

YOUBOOK 2LIVESPACE BLOGJAM 1UBQTS TXT 1

SKINUX 0

// Problem#: 1447// Submission#: 3311837// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <iostream>#include <vector>#include <algorithm>#include <stdio.h>#include <math.h>#include <string.h>#include <string>#include <queue>#include <set>using namespace std;struct P {    set<string> students;    string name;    P(string n) {        students.clear();        name = n;    }};vector<P> projects;set<string> appear;set<string> toDelete;int N = -1;bool cmp(const P & p1, const P & p2) {    if (p1.students.size() != p2.students.size())        return p1.students.size() > p2.students.size();    else        return p1.name < p2.name;}void solve() {    for (int i = 0; i <= N; i++) {        for (set<string>::iterator iter = toDelete.begin(); iter != toDelete.end(); iter++) {            set<string>::iterator pos = projects[i].students.find(*iter);            if (pos != projects[i].students.end()) {                projects[i].students.erase(pos);            }        }    }    sort(projects.begin(), projects.begin() + N + 1, cmp);    for (int i = 0; i <= N; i++) {        cout << projects[i].name << " " << projects[i].students.size() << endl;    }}int main() {    std::cout.sync_with_stdio(false);    string temp;    while (1) {        getline(cin, temp);        if (temp[0] == '0') break;        if (temp[0] == '1') {            solve();            N = -1;            projects.clear();            appear.clear();            toDelete.clear();            continue;        }        if ('A' <= temp[0] && temp[0] <= 'Z') {            projects.push_back(P(temp));            N++;            continue;        }        if ('a' <= temp[0] && temp[0] <= 'z') {            if (appear.find(temp) != appear.end()) {                if (projects[N].students.find(temp) == projects[N].students.end()) {                    toDelete.insert(temp);                }            } else {                projects[N].students.insert(temp);                appear.insert(temp);            }            continue;        }    }    return 0;}                                 


0 0