hdu 1242 disney (map模拟)
来源:互联网 发布:阿尔法营销软件 编辑:程序博客网 时间:2024/06/08 17:51
disney
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1039 Accepted Submission(s): 299
Problem Description
A new machine was introduced into disney world. Every day, there is a long queue because of its function. Everyone can input their score or update their score. If you want to know the maximum or the average, it can help you, too.What's more, if you don't want that your score be saw, you can delete your register from it. Since the new machine was introduced, everyone be more hard.
Input
The input contain only one case.
There are kinds of format that show different functions:
(1)NEW name score(you can use it to input your score or update your score)
name: the name of current user.The length of the name is no longer than 8.
score: the score of current user.(0<score<=100)
(2)AVERAGE(you can use is to get the average score)
(3)MAX(you can use is to get the maximal score and whose score is the maximum.)
(4)DELETE name:delete the name and its record too.
name: the name of current user.The length of the name is no longer than 8.
(5)QUIT(this command is used to turn off the machine,is the end of the input)
There are kinds of format that show different functions:
(1)NEW name score(you can use it to input your score or update your score)
name: the name of current user.The length of the name is no longer than 8.
score: the score of current user.(0<score<=100)
(2)AVERAGE(you can use is to get the average score)
(3)MAX(you can use is to get the maximal score and whose score is the maximum.)
(4)DELETE name:delete the name and its record too.
name: the name of current user.The length of the name is no longer than 8.
(5)QUIT(this command is used to turn off the machine,is the end of the input)
Output
(1)For "NEW name score" , if it's there is a lack of record of the user. print "A new record".else print "update succeed".
(2)For "AVERAGE" , you should print the average score rounded to two digits after the decimal point.if there are none record in the machine,the average is 0.00;
(3)For "MAX" , you should first print the maximal score and the number that whose score is the maximum, then print all of their names Lexicographicly, and each name owns a single line. If there isn't any record in the machine,just output"0 0".
(4)For "DELETE name" , if there is a lack of record of the user. print "no such record".else print "delete succeed".
The population of disney is no more than 100.
(2)For "AVERAGE" , you should print the average score rounded to two digits after the decimal point.if there are none record in the machine,the average is 0.00;
(3)For "MAX" , you should first print the maximal score and the number that whose score is the maximum, then print all of their names Lexicographicly, and each name owns a single line. If there isn't any record in the machine,just output"0 0".
(4)For "DELETE name" , if there is a lack of record of the user. print "no such record".else print "delete succeed".
The population of disney is no more than 100.
Sample Input
NEW mickey 99NEW mini 88MAXAVERAGEDELETE winnieQUIT
Sample Output
A new recordA new record99 1mickey93.50no such record
Author
kiki
Source
HDU 2007-11 Programming Contest
思路:用map来模拟。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <vector>using namespace std;int main(){ string n; map<string,int> m; map<string,int> ::iterator it; double sum=0; while(cin>>n) { if(n=="NEW") { string name; int grade; cin>>name; cin>>grade; it=m.find(name); if(it==m.end()) { m[name]=grade; printf("A new record\n"); sum+=grade; } else { printf("update succeed\n"); sum-=m[name]; sum+=grade; m[name]=grade; } } else if(n=="AVERAGE") { if(m.size()==0) { printf("0.00\n"); } else { double ave=sum/(m.size()*1.0); printf("%.2lf\n",ave); } } else if(n=="MAX") { if(m.size()==0) { printf("0 0\n"); } else { int maxn=m.begin()->second; for(it=m.begin();it!=m.end();it++) { if(it->second>maxn) maxn=it->second; } vector<string> f; f.clear(); for(it=m.begin();it!=m.end();it++) { if(it->second==maxn) { f.push_back(it->first); } } sort(f.begin(),f.end()); printf("%d %d\n",maxn,f.size()); for(int i=0;i<f.size();i++) { cout<<f[i]<<endl; } } } else if(n=="DELETE") { string nam; cin>>nam; it=m.find(nam); if(it==m.end()) { printf("no such record\n"); } else { printf("delete succeed\n"); sum-=it->second; m.erase(it); } } else break; } return 0;}
阅读全文
0 0
- hdu 1242 disney (map模拟)
- disney (map模拟)
- hdu 2142 disney(模拟)
- HDU 2142 - disney
- hdu 2142 disney
- HDU Disney's FastPass
- hdu - 4329 - MAP - 模拟
- HDU 5186 || 模拟map
- hdu 4114 Disney's FastPass
- Disney
- HDU 4114 Disney's FastPass(状压dp)
- hdu 4114 Disney's FastPass 状压dp
- HDU 4114 Disney's FastPass Time
- hdu 4272 LianLianKan(模拟dfs+map)
- HDU 3347 Calculate the expression 模拟 map
- hdu Disney's FastPass(状态压缩dp)
- Hdu 4114 Disney's FastPass(状压dp)
- HDU Disney's FastPass(状态压缩DP)
- java学习路线
- 51node-1006-最长公共子序列Lcs
- 数据结构与算法笔记之--算法绪论
- 94. Binary Tree Inorder Traversal
- 开源个.NetCore写的
- hdu 1242 disney (map模拟)
- 《剑指offer》牛客网java题解-调整数组顺序使奇数位于偶数前面
- ros indigo 学习笔记--->
- 初识Vue.js
- 逻辑地址、线性地址、物理地址和虚拟地址理解
- 音视频编解码相关知识学习
- 【JAVA 提高班之三】异常处理
- 回溯法简介
- 一、高并发秒杀API简介与业务分析