Problem G: 开个餐馆算算账
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 673 Solved: 337
[ Submit][ Status][ Web Board]
Description
小明创业了!他开了一家餐馆,每天客人还挺多的。每天下班后,他都要算算今天总共收入多少钱,但是手工算太麻烦了,所以他来向你求助了。
Input
第1行N>0,表示餐馆提供N个菜品。
之后N行,每行包括2部分:菜名(不含空白符)及每份菜品的价格。
接着是M>0,表示今天接待的客人数。
每个客人的输入份三部分,第1行是客人的姓名(不含空白符),第2行是客人点的菜品的种类数K,之后K行是客人点的菜品名及份数。
Output
第一行输出Guest Price。
之后按照客人姓名从小到大的顺序(没有重名的顾客),依次输出每个客人消费了多少钱,消费额保留2位小数。
输出时,姓名左对齐,宽度为所有客人姓名的最大长度加1。
Sample Input
10
Yu-Shiang-Shredded-Pork 20
sweet-sour-Shredded-potato 15
Pie 0.50
Steamed-Rice 1.50
Tomato-and-Egg-Soup 17
Spareribs-with-brown-sauce 55
Sauteed-Sliced-Lamb-with-Scallion 60
Stir-fried-bean-sprouts 14
Moo-Shu-Pork 18
Deep-Fried-Dough-Sticks 2.50
3
Zhangsan
4
Yu-Shiang-Shredded-Pork 1
sweet-sour-Shredded-potato 1
Pie 3
Steamed-Rice 1
LiSi
2
Moo-Shu-Pork 1
Deep-Fried-Dough-Sticks 4
WangWu
3
Tomato-and-Egg-Soup 1
Spareribs-with-brown-sauce 1
Sauteed-Sliced-Lamb-with-Scallion 1
Yu-Shiang-Shredded-Pork 20
sweet-sour-Shredded-potato 15
Pie 0.50
Steamed-Rice 1.50
Tomato-and-Egg-Soup 17
Spareribs-with-brown-sauce 55
Sauteed-Sliced-Lamb-with-Scallion 60
Stir-fried-bean-sprouts 14
Moo-Shu-Pork 18
Deep-Fried-Dough-Sticks 2.50
3
Zhangsan
4
Yu-Shiang-Shredded-Pork 1
sweet-sour-Shredded-potato 1
Pie 3
Steamed-Rice 1
LiSi
2
Moo-Shu-Pork 1
Deep-Fried-Dough-Sticks 4
WangWu
3
Tomato-and-Egg-Soup 1
Spareribs-with-brown-sauce 1
Sauteed-Sliced-Lamb-with-Scallion 1
Sample Output
Guest Price
LiSi 28.00
WangWu 132.00
Zhangsan 38.00
LiSi 28.00
WangWu 132.00
Zhangsan 38.00
HINT
Append Code
本题用map映射较为简单,一个映射用于存储菜名和价格,一个用于储存姓名和消费总额,然后再输出即可,代码如下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int max=0;
cin>>n;
string s;
double ram;
map<string,double> p1;
for(int i=0;i<n;i++)
{
cin>>s>>ram;
p1.insert(make_pair(s,ram));
}
map<string,double> p2;
int m;
cin>>m;
for(int i=0;i<m;i++)
{
double sum=0;
string name;
cin>>name;
int k;
cin>>k;
if(name.length()>max)
max=name.length();
for(int j=0;j<k;j++)
{
string ss;
cin>>ss;
int num;
cin>>num;
sum+=num*p1[ss];
}
p2.insert(make_pair(name,sum));
}
//sort(ss,ss+m);
cout<<setiosflags(ios::left)<<setw(max+1)<<"Guest"<<"Price"<<endl;
map<string,double>::iterator it;
for(it=p2.begin();it!=p2.end();it++)
cout << setiosflags(ios::left) << setw(max+1) << it->first << fixed << setprecision(2) << it->second << endl;
//for(int i=0;i<m;i++){
// cout<<setiosflags(ios::left)<<setw(9)<<ss[i]<<setprecision(2)<<fixed<<pp[ss[i]]<<endl;
// }
}