2013
12-29

# disney

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.

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)

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)

NEW mickey 99
NEW mini 88
MAX
AVERAGE
DELETE winnie
QUIT

A new record
A new record
99 1
mickey
93.50
no such record

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
map<string,int>m;
int main()
{
m.clear();
map<string,int>::iterator it,se;
string s;
string str;
double sum=0;
while(cin>>s)
{
if(s=="QUIT")
break;
if(s=="NEW")
{
cin>>str;
se=m.find(str);
if(se==m.end())
printf("A new record\n");
else
{
sum-=m[str];
printf("update succeed\n");
}
}
else if(s=="MAX")
{
vector<string>v;
v.clear();
int mx=m.begin()->second;
for(it=m.begin();it!=m.end();it++)
mx=max(mx,it->second);
for(it=m.begin();it!=m.end();it++)
{
if(it->second==mx)
{
v.push_back(it->first);
}
}
printf("%d %d\n",mx,v.size());
sort(v.begin(),v.end());
vector<string>::iterator ii=v.begin();
for(;ii!=v.end();ii++)
cout<<*ii<<endl;
}
else if(s=="AVERAGE")
{
printf("%.2lf\n",sum/m.size());
}
else if(s=="DELETE")
{
cin>>str;
se=m.find(str);
if(se==m.end())
printf("no such record\n");
else
{
sum-=se->second;
m.erase(se);
printf("delete succeed\n");
}
}
}
return 0;
}

1. 第一题是不是可以这样想，生了n孩子的家庭等价于n个家庭各生了一个1个孩子，这样最后男女的比例还是1:1