All pastes #294044 Raw Edit

Someone

public c v1 · immutable
#294044 ·published 2006-12-28 03:14 UTC
rendered paste body
/*ID: superso1LANG: CTASK: gift1*/#include <stdio.h>#include <stdlib.h>#include <string.h>int match_name(char *name, char library[10][14]) {	int i=0;	for(;i<10;i++) {		if(!strcmp(library[i],name))			return i;	}	return -1;}int main(void){	FILE *fin=fopen("gift1.in", "r");	FILE *fout=fopen("gift1.out", "w");	int NP;	char names[10][14];	int money[10];	int f=0;	int i=0;	char giver[14];	int amount_give;	int people;	char recv[10];	memset(money,0,10*sizeof(int));		//first see how many people there are	fscanf(fin,"%d",&NP);		//store the names	for(;f<NP;f++)		fscanf(fin,"\n%s",names[f]);	for(f=0;f<NP;f++) {		fscanf(fin,"\n%s",giver); //the current giver		fscanf(fin,"\n%d %d",&amount_give,&people); //get the amount of money, and number of people to give to		money[match_name(giver,names)]-=amount_give; //deduction for gift		if(people>0) money[match_name(giver,names)]+=amount_give%people; //amount left over after giftfprintf(stderr,"=HI=\n");		//give the recipients their cash		for(i=0;i<people;i++) {fprintf(stderr,"%d\n",people);	system("read");		fscanf(fin,"\n%s",recv);			money[match_name(recv,names)]+=amount_give/people;//fprintf(stderr,"%s giving %d to %s\n",giver,amount_give/people,recv);		}fprintf(stderr,"NP==%d,f==%d\n",NP,f);	}		for(i=0;i<NP;i++)		fprintf(fout,"%s %d\n",names[i],money[i]);		fclose(fout);	fclose(fin);	exit(0);}