Sicily 1447. Open Source

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 TXT
tthumb
LIVESPACE BLOGJAM
philton
aeinstein
YOUBOOK
j97lee
sswxyzy
j97lee
aeinstein
SKINUX
1
0

Sample Output

YOUBOOK 2
LIVESPACE BLOGJAM 1
UBQTS 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值