Problem B: 开个餐馆算算账

时间:2023-03-09 14:35:38
Problem B: 开个餐馆算算账

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

Sample Output

Guest Price LiSi 28.00 WangWu 132.00 Zhangsan 38.00
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <iomanip>
#include <map>
using namespace std;
int imax=0;
bool cmp(string a,string b)
{
    return a<b;
}
int main()
{
   string pename[20];
   int k;
   cin>>k;
   map<string,double> cai;
   map<string,double> guest;
   string t;
   double n;
   while(k--)
   {
       cin>>t>>n;
       cai[t]=n;
   }
   int users,orders;
   cin>>users;
   for(int i=0;i<users;i++)
   {
       cin>>t;
       imax=imax>t.size()?imax:t.size();
       pename[i]=t;
       guest[t]=0;
       cin>>orders;
       int num;
       string c;
       for(int j=0;j<orders;j++)
       {
           cin>>c>>num;
           guest[t]+=(cai[c]*num);
       }
   }
   sort(pename,pename+users,cmp);
   cout<<setiosflags(ios::left)<<setw(imax+1)<<"Guest"<<"Price"<<endl;
   for(int i=0;i<users;i++)
   {
       cout<<setw(imax+1)<<std::left<<pename[i]<<setprecision(2)<<setiosflags(ios::fixed)<<guest[pename[i]]<<endl;
   }
}