NOJ [1118] Marisa's Affair
来源:互联网 发布:php分类源码 编辑:程序博客网 时间:2024/05/16 01:28
- 问题描述
- Everyone knows that Kirisame Marisa(きりさめ·まりさ) often has affaires with other witches in TouHou.
For example, she has an affair with Reimu today and tomorrow is Flandre.
You have to make clear that how many witches she has affairs with. - 输入
- This problem has several cases.
The first line of each case contains an integer N(0 < N <= 5000).
Then follows N lines. The ith has a name NAMEi and an integer Hi(0 < Hi < 20000), means at the ith day Marisa has an affair with NAMEi, and NAMEi increases Hi likability.
You can consider that every name only contains uppercase and lowercase letters, and not longer then 20; - 输出
- For each case, you should output like that:
At the first line, you should output how many witches Marisa has affaires with;
Then each line output like that:
The name of the witch, the likability with that witch and the time(s) they have affaires. Order by likability descending.
If their likabilities are the same, then order by affair times descending.
If their likabilities and affair times are the same, then order by lexicographical order increasing.看懂题之后,其实这是一道水题上代码#include<stdio.h>#include<iostream>#include<map>#include<string.h>#include<algorithm>using namespace std;struct affair{char name[25];long long likability,times;}witches[5010];char temp[22];int cmp(affair a,affair b){if(a.likability != b.likability)return a.likability > b.likability;else{if(a.times != b.times)return a.times > b.times;elsereturn strcmp(a.name,b.name)<0;}}int main(){int n,i;while(~scanf("%d",&n)){long long d, k=1;map<string,int>affairs;//affairs.clear();for(i=0;i<=n;i++){witches[i].likability=0;witches[i].times=0;}for(i=0;i<n;i++){scanf("%s %lld",temp,&d);if(affairs[temp]==NULL){affairs[temp]=k;strcpy(witches[k].name,temp);witches[k].times=1;witches[k].likability+=d;k++;}else{witches[affairs[temp]].likability+=d;witches[affairs[temp]].times++;}}sort(witches+1,witches+k,cmp);printf("%d\n",k-1 );for(i=1;i<k;i++)printf("%s %lld %lld\n",witches[i].name,witches[i].likability,witches[i].times);}return 0;}
0 0
- NOJ [1118] Marisa's Affair
- HDOJ 5448 Marisa’s Cake
- HDU 5448 Marisa’s Cake
- 【HDU 5448】Marisa’s Cake
- hdu 5448 Marisa’s Cake(几何+凸包)
- hdu 5448 Marisa’s Cake(计算几何加推公式)
- HDU 5448 Marisa's Cake(计算几何)
- NOJ [1085] kiki's game
- NOJ [1114] Alice's Puppets
- NOJ [1184] Elaine's Queue
- NOJ [1116] Flandre's Passageway
- NOJ [1133] Farmer\'s Pearls
- NOJ [1116] Flandre\'s Passageway
- NOJ [1120] Reimu\'s Teleport
- 2015 ACM/ICPC Asia Regional Changchun Online 1012 hdu5448 Marisa’s Cake
- HDU 5448 Marisa’s Cake(n个点中任意点组成的多边形面积之和)
- hdu5448-Marisa’s Cake 构成的所有多边形面积的和
- NOJ [1265] Flandre's Second Escape
- 条件随机场
- DevExpress13.1汉化
- ArcGIS 10.3 for Server新特性介绍
- UTF8编码区间
- android 3G pppd 调试记录
- NOJ [1118] Marisa's Affair
- EL表达式
- 苹果Mac OS X系统常用多点触摸板操作手势
- JAVA 集合操作
- 在osg场景中使用GLSL语言——一个例子
- GLOOX 1.0 API ---框架
- 安全相关书籍、站点
- sharepoint 2007 2010 2013 创建网站服务器不支持此语言异常
- VC++、MFC中最好的开源项目