All pastes #294010 Raw Edit

Miscellany

public c v1 · immutable
#294010 ·published 2006-12-28 02:27 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);		//first see how many people there are	fscanf(fin,"%d",&NP);	fseek(fin,1,SEEK_CUR);		//store the names	for(;f<NP;f++)		fscanf(fin,"%s\n",names[f]);	for(f=0;f<NP;f++) {		fscanf(fin,"%s\n",giver); //the current giver		fscanf(fin,"%d %d\n",&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,"%s\n",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);}