Open Source
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1860 Accepted: 757
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
Source
Waterloo Local Contest, 2007.7.14
問題鏈接:POJ3297 UVA11239 Open Source
問題簡述:(略)
問題分析:
學生選課有關的問題,每個學生只能選一門課。大寫開頭字符串是課程名字,小寫開頭字符串是人名。如果課程後面有多個相同名字算一個;如果一個人選多門課,則他選不上課。計算輸出課程和每門課選課人數。
本題使用STL的map來實現。
程序說明:(略)
參考鏈接:(略)
題記:(略)
AC的C++語言程序如下:
/* POJ3297 UVA11239 Open Source */
#include <iostream>
#include <algorithm>
#include <map>
#include <cctype>
#include <cstdio>
using namespace std;
const int N = 100;
struct Project {
string name;
int cnt;
} proj[N + 1];
int cmp(Project a, Project b)
{
return a.cnt == b.cnt ? a.name < b.name : a.cnt > b.cnt;
}
int main()
{
string s;
while(getline(cin, s) && s[0] != '0') {
map<string, int> m;
map<string, int> special;
int cnt = 1;
for(;;) {
proj[cnt].name = s;
proj[cnt].cnt = 0;
for(;;) {
getline(cin, s);
if(s.size() == 1 && s[0] == '1') break;
if(islower(s[0]) || isdigit(s[0])) {
if(m[s] == 0) {
m[s] = cnt;
proj[cnt].cnt++;
} else {
if(m[s] != cnt && special[s] == 0) {
special[s] = 1;
if(proj[m[s]].cnt > 0)
proj[m[s]].cnt--;
}
}
} else
break;
}
cnt++;
if(s[0] == '1') break;
}
sort(proj + 1, proj + cnt, cmp);
for(int i = 1; i < cnt; i++)
printf("%s %d\n", proj[i].name.c_str(), proj[i].cnt);
}
return 0;
}