C++ 台中區 106-2 算帳

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