国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

disney (map模擬)

2019-11-06 06:18:47
字體:
供稿:網(wǎng)友
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. InputThe 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) 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. Sample Input
NEW mickey 99NEW mini 88MAXAVERAGEDELETE winnieQUITSample Output
A new recordA new record99 1mickey93.50

no 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;}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 蓝山县| 建始县| 平凉市| 常德市| 景宁| 丹寨县| 诸暨市| 万载县| 华池县| 泗阳县| 张家港市| 嵊泗县| 仙桃市| 云阳县| 关岭| 桃园县| 祁连县| 泽库县| 天祝| 县级市| 翁源县| 松潘县| 海口市| 修武县| 托克逊县| 镇远县| 西乌珠穆沁旗| 砚山县| 都兰县| 改则县| 武邑县| 分宜县| 精河县| 河东区| 阿城市| 达拉特旗| 刚察县| 宁蒗| 平陆县| 淅川县| 新乡市|