USACO--1.1Greedy Gift Givers+模拟

简单模拟题。注意0%0是非法运算

代码如下:

/* ID: 15674811 LANG: C++ TASK: gift1 */

#include<iostream>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<map>
using namespace std;

int main()
{
    ofstream fout("gift1.out");
    ifstream fin("gift1.in");
    char name[15][20];
    int acount[20];
    memset(acount,0,sizeof(acount));
    map<string,int>m;
    int n;
    while(fin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            fin>>name[i];
            m[name[i]]=i;
        }
        char tmp[20];
        while(fin>>tmp)
        {
            int t=m[tmp];
            int k,num;
            fin>>k>>num;
            if(k==0&&num==0)
                continue;
            acount[t]-=k;
            acount[t]+=k%num; ///0%0是非法运算
            for(int i=1;i<=num;i++)
            {
                fin>>tmp;
                acount[m[tmp]]+=k/num;
            }
        }
        for(int i=1;i<=n;i++)
            fout<<name[i]<<" "<<acount[i]<<endl;
    }
  return 0;
}

你可能感兴趣的:(USACO--1.1Greedy Gift Givers+模拟)