码迷,mamicode.com
首页 > 其他好文 > 详细

usaco Greedy Gift Givers

时间:2015-08-26 01:34:57      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

/*
ID: modengd1
PROG: gift1
LANG: C++
*/
#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char names[30][20];
int acount[30];
int counter,N;
int getIndex(char name[20])
{
    for(int i=0;i<counter;i++)
    {
        if(strcmp(names[i],name)==0)
            return i;
    }
    strcpy(names[counter],name);
    return counter++;
}

int main()
{
    freopen("gift1.in","r",stdin);
    freopen("gift1.out","w",stdout);
    int a,b,money;
    scanf("%d",&N);
    memset(acount,0,sizeof(acount));
    counter=0;
    char name[20];
    for(int i=0;i<N;i++)
    {
        scanf("%s",name);
        getIndex(name);
    }
    for(int j=0;j<counter;j++)
    {
        scanf("%s",name);
        int giver=getIndex(name);
        scanf("%d%d",&a,&b);
        money=0;
        if(b!=0)
        {
            acount[giver]-=((a)-(a%b));
            money=a/b;
        }
        for(int i=0;i<b;i++)
        {
            scanf("%s",name);
            int receive=getIndex(name);
            acount[receive]+=money;
        }
    }
    for(int i=0;i<counter;i++)
    {
        for(int j=0;names[i][j]!=‘\0‘;j++)
            printf("%c",names[i][j]);
        putchar(‘ ‘);
        printf("%d\n",acount[i]);
    }
    return 0;
}

  

usaco Greedy Gift Givers

标签:

原文地址:http://www.cnblogs.com/modengdubai/p/4758964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!