P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

一道非常愚蠢的模拟题

值得庆祝的是,从题解找到了比较两个字符串是否相同的函数

if(strcmp(a,s1[j])==0){
				b[j]-=x;
				break;
			}	

 数据费心费力为了卡我这个只比较第一二三个字母的造了这么一组数据

2
someguy
someotherguy
someotherguy
1500 1
someguy
someguy
500 1
someotherguy

答案:

someguy 1000
someotherguy -1000

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
char s1[13][1002],a[109];
int b[14],n,x,y;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        cin>>s1[i];
    for(int i=1;i<=n;i++){
        cin>>a>>x>>y;
        if(y==0)    continue;
        int mo=x/y;
        x=mo*y;
        for(int j=1;j<=n;j++){
            if(strcmp(a,s1[j])==0){
                b[j]-=x;
                break;
            }    
        }
        for(int j=1;j<=y;j++){
            cin>>a;
            for(int k=1;k<=n;k++)
                if(strcmp(a,s1[k])==0){
                    b[k]+=mo;
                    break;
                }    
        }
    }
    for(int i=1;i<=n;i++)
        cout<<s1[i]<<' '<<b[i]<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/jindui/p/11634650.html