UVA 11239
来源:互联网 发布:linux的snmp 详解 编辑:程序博客网 时间:2024/06/06 02:17
Thinking: Here we used the structure "map" to achieve our goal. Quite easy actually :)
Remember to clear the map in next case.
AC code:
#include<iostream>#include<cstring>#include<cmath>#include<map>#include<algorithm>#include<vector>#include<stack>#include<queue>#include<string>#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)<(b)?(a):(b))using namespace std;struct pro{char name[105];map<string, int> student;};pro project[105]; bool cmp(const pro &a, const pro &b){if (a.student.size() == b.student.size())return strcmp(a.name, b.name) < 0;else return a.student.size() > b.student.size();/*if (a.student.size() > b.student.size())return true;else if (a.student.size() < b.student.size())return false;else return a.name < b.name;*/}int main(){//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);char input[100];char temp[100];bool lastone = false;while (!lastone){map<string, bool> abandon;int count_pro = 0;while (gets(input)){if (input[0] == '1')//deal with data got till now{sort(project + 1, project + 1 + count_pro, cmp);for (int i = 1; i <= count_pro; i++)printf("%s %d\n", project[i].name, project[i].student.size());break;}if (input[0] == '0'){lastone = true;break;}if (input[0] >= 'A'&&input[0] <= 'Z')//input is project{project[++count_pro].student.clear();strcpy(project[count_pro].name, input);continue;}else{if (abandon.find(input) == abandon.end()){if (project[count_pro].student.find(input) == project[count_pro].student.end())//this student is not in this before{for (int i = 1; i < count_pro; i++){if (project[i].student.find(input) != project[i].student.end()){project[i].student.erase(input);abandon[input] = true;}}if (abandon.find(input) == abandon.end())project[count_pro].student[input] = 1;}}}}}return 0;}
1 0
- UVA 11239
- UVa 11239
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 在windows下安装scala出现错误:找不到或无法加载主类 scala.tools.nsc.MainGenericRunner
- I2C总线
- Qt 程序在 Windows 下的发布
- LeetCode---Counting Bits解题分析
- java.io.RandomAccessFile
- UVA 11239
- 教你如何使用ViewPager+Fragment一步步打造顶部导航界面滑动效果
- Android静态安全检测 -> 随机数使用不安全
- LeetCode Remove Nth Node From End of List
- typeof()
- 关于使用百度地图SDK报错java.lang.UnsatisfiedLinkError的解决办法
- Centos下daemontools监控logstash进程
- mac和phy的关系(三)
- 【DS】Hash表及布隆过滤器