Problem Type : Ad hoc
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<cstring>
#define MAX 1000
using namespace std;
map<string,long int>mymap;
int main()
{
string s ,s2,s1[MAX];
int i,j,k,n,test,arr[MAX],money,in,sum,pai,x,cou=0;
while(scanf("%d",&test)==1)
{
getchar();
mymap.clear();
for(i=0;i<test;i++)
{
cin>> s;
s1[i]=s;
mymap[s]=i;
arr[i]=0;
}
for(i=0;i<test;i++)
{
cin >> s >> money >> n;
if(n==0)
continue;
x = mymap[s];
arr[x]-=money;
in = money/n;
pai = in*n;
sum = money-pai;
arr[x]+=sum;
for(j=0;j<n;j++)
{
cin >> s2;
x = mymap[s2];
arr[x]+=in;
}
}
if(cou!=0)
{
printf("\n");
}
cou++;
for(i=0;i<test;i++)
{
x=mymap[s1[i]];
cout << s1[i] << ' ' <<arr[x] <<endl;
}
}
}
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<cstring>
#define MAX 1000
using namespace std;
map<string,long int>mymap;
int main()
{
string s ,s2,s1[MAX];
int i,j,k,n,test,arr[MAX],money,in,sum,pai,x,cou=0;
while(scanf("%d",&test)==1)
{
getchar();
mymap.clear();
for(i=0;i<test;i++)
{
cin>> s;
s1[i]=s;
mymap[s]=i;
arr[i]=0;
}
for(i=0;i<test;i++)
{
cin >> s >> money >> n;
if(n==0)
continue;
x = mymap[s];
arr[x]-=money;
in = money/n;
pai = in*n;
sum = money-pai;
arr[x]+=sum;
for(j=0;j<n;j++)
{
cin >> s2;
x = mymap[s2];
arr[x]+=in;
}
}
if(cou!=0)
{
printf("\n");
}
cou++;
for(i=0;i<test;i++)
{
x=mymap[s1[i]];
cout << s1[i] << ' ' <<arr[x] <<endl;
}
}
}
No comments:
Post a Comment