All pastes #294024 Raw Edit

Someone

public c v1 · immutable
#294024 ·published 2006-12-28 02:46 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		money[match_name(giver,names)]+=amount_give%people; //amount left over after gift		//give the recipients their cash		for(i=0;i<people;i++) {			fscanf(fin,"\n%s",recv);			money[match_name(recv,names)]+=amount_give/people;		}	}		for(i=0;i<NP;i++)		fprintf(fout,"%s %d\n",names[i],money[i]);		fclose(fout);	fclose(fin);	exit(0);}