disney (map模拟)
来源:互联网 发布:sql怎么安装 编辑:程序博客网 时间:2024/06/06 20:25
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.
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)
(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.
NEW mickey 99NEW mini 88MAXAVERAGEDELETE winnieQUIT
A new recordA new record99 1mickey93.50no such record
#include <iostream>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <algorithm>#include <vector>#include <string>#include <cstring>#include <sstream>#define INF 100000000using namespace std;map<string,int> M;double sum;int main(){ string s; map<string,int>::iterator i; while(cin>>s) { if(s=="QUIT") { return 0; } else if(s=="NEW") { string name; cin>>name; int grade; cin>>grade; i=M.find(name); if(i==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(s=="AVERAGE") { if(M.size()==0) { printf("0.00\n"); } else { double ave=sum*1.0/M.size(); printf("%.2f\n",ave); } } else if(s=="MAX") { if(M.size()==0) { printf("0 0\n"); } else { map<string,int>::iterator it; int maxx=M.begin()->second; for(it=M.begin();it!=M.end();it++) { if(it->second>maxx) maxx=it->second; } vector<string> b; b.clear(); for(it=M.begin();it!=M.end();it++) { if(it->second==maxx) { b.push_back(it->first); } } sort(b.begin(),b.end()); printf("%d %d\n",maxx,b.size()); for(int i=0;i<b.size();i++) { cout<<b[i]<<endl; } } } else if(s=="DELETE") { string name; cin>>name; i=M.find(name); if(i==M.end()) { printf("no such record\n"); } else { printf("delete succeed\n"); sum-=M[name]; M[name]=0; map<string,int>::iterator it; M.erase(i); } } } return 0;}
0 0
- disney (map模拟)
- hdu 1242 disney (map模拟)
- hdu 2142 disney(模拟)
- Disney
- Regarding Disney
- Google Map模拟
- hdu - 4329 - MAP - 模拟
- 用 js模拟 Map
- js 模拟Map类
- js模拟Map
- HDU 5186 || 模拟map
- javascript模拟map
- js模拟Map
- javascript模拟实现Map
- JS模拟Map(2)
- zjnu1707 TOPOVI (map+模拟)
- 【NOIP模拟】Map
- C++ 模拟Map
- 利用axis请求webservice接口
- mongoDB——GridFS存储机制
- opencv激光点追踪代码
- 全面了解Nginx到底能做什么
- MySQL中的bit类型知道多少呢?
- disney (map模拟)
- DFS学习归纳总结
- 使用SQL链接服务器在不同局域网下实现数据库的数据传递
- Oracle到MySQL数据库迁移之--主键生成策略替换
- JS基础---用户注册高亮显示
- JavaWeb从入门到精通(四)-会话管理
- Android 硬编码 备注
- 图的m着色问题
- 【Linux就该这么学】在线培训第一期视频教程价值2400元