0%

C++ 台中區 106-2 算帳

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<map>
#include<cmath>
#include<string>
using namespace std;
#define F first
#define S second

int main(){
map<string,double> s,amount;
string p;
double sum=0;
while(cin>>p && p!="0000000000"){
int a,pr;
cin>>pr>>a;
s[p]=pr;
amount[p]+=a;
}

for(map<string,double>::iterator t=s.begin();t!=s.end();t++){
pair<string,double> a=*t;
sum+=a.S*amount[a.F];
switch(a.F[0]){
case 'X':
if(amount[a.F]>=2)
sum-=a.S*floor(amount[a.F]*0.5);
break;
case 'Y':
if(amount[a.F]>=2)
sum-=a.S*floor(amount[a.F]*0.5)*0.5;
break;
}
}
cout<<sum<<"\n";
return 0;
}