a line for each person in the group consisting of the name of the person, the amount of money spent on gifts, the number of people to whom gifts are given, and the names of those to whom gifts are given.
Your input would be invalid, because if the person never gave out a gift, his money input would always be zero (because he/she didn't spend any money) and not a positive integer.
thanks 4 the help, I just make a little stupid fault
I use mod calculation to determine how much one should take money for himself, so I give "if the modulo not zero", but I forgot to write the "else" code. After I read this message board, I realize that matter, but again... I write it wrong ^-^;
And got accepted. Weird, but it worked. I know there's an extra name added because I put a check in my program. If the first character of the next token was a letter, I entered a spinlock. It returned TLE, so that's how I knew.
Im new here , and my program solve the tests inputs in the problem
statement , but i got WA.. why ???
Greetings from Peru
Thanks in advance
{ GREEDY GIFT GIVERS }
PROGRAM Greedy(INPUT, OUTPUT);
CONST
MAX = 10;
TYPE
str12 = STRING[12];
TStrings = ARRAY[1..MAX] OF str12;
TPerson = RECORD
name : STRING;
nfriends : INTEGER;
friends : TStrings;
inimoney, finmoney : INTEGER;
END;
TPeople = ARRAY[1..MAX] OF TPerson;
{ Procedures / Functions }
FUNCTION
SearchFriend(
VAR group : TPeople;
npeople : INTEGER;
friendname : STRING
) : INTEGER;
VAR
posfriend, posi : INTEGER;
BEGIN
posfriend := -1;
FOR posi:=1 to npeople DO BEGIN
IF ( POS(friendname, group[posi].name) > 0 ) THEN BEGIN
posfriend := posi;
END;
END;
SearchFriend := posfriend;
END;
PROCEDURE
CalcFinalMoney(
VAR group : TPeople;
npeople : INTEGER;
posperson : INTEGER
);
VAR
giftmoney : INTEGER;
friend, posfriend : INTEGER;
BEGIN
giftmoney := 0;
{ Distribute its money equally }
IF (group[posperson].inimoney <> 0) THEN
giftmoney := group[posperson].inimoney DIV group[posperson].nfriends;
{ Keep the remainder }
IF (group[posperson].inimoney <> 0) THEN
group[posperson].finmoney := group[posperson].finmoney +
( group[posperson].inimoney MOD
group[posperson].nfriends );
FOR friend :=1 TO group[posperson].nfriends DO BEGIN
FUNCTION
ExtractName(
VAR names : STRING
):STRING;
VAR
posblanco : INTEGER;
nam : STRING;
BEGIN
posblanco := POS(' ', names);
IF (posblanco > 0) THEN BEGIN
nam := COPY(names, 1, posblanco-1);
DELETE(names, 1, posblanco);
END
ELSE
nam := names;
ExtractName := nam;
END;
PROCEDURE
GreedyGivers(
VAR group : TPeople;
npeople : INTEGER;
strnames : STRING
);
VAR
nperson, i : INTEGER;
name : STRING;
BEGIN
FOR nperson:=1 TO npeople DO BEGIN
{ Calculate person's final money }
CalcFinalMoney(group, npeople, nperson);
END;
{ Print names : strnames }
FOR i:=1 TO npeople DO BEGIN
name := ExtractName(strnames);
nperson := SearchFriend(group, npeople, name);
WRITELN(OUTPUT, group[nperson].name, ' ', (group[nperson].finmoney-
group[nperson].inimoney):1);
END;
END;
FUNCTION
ReadData : STRING;
VAR
c : CHAR;
str : STRING;
BEGIN
REPEAT
READ(INPUT, c);
UNTIL ( (c <> ' ')
AND (c <> #10)
AND (c <> #13)) ;
str := '';
WHILE ( ( c <> ' ' )
AND ( c <> #10 )
AND ( c<> #13 )
AND (c <> #26) ) DO BEGIN
str := str + c;
READ(INPUT, c);
END;
ReadData := str;
END;
{ PP }
VAR
group : TPeople;
i, j, cod, npeople : INTEGER;
strnames : STRING;
BEGIN
WHILE NOT EOF(INPUT) DO BEGIN
READLN(INPUT, npeople);
READLN(INPUT, strnames);
FOR i:= 1 TO npeople DO BEGIN
group.name := ReadData;
VAL(ReadData, group.inimoney, cod);
VAL(ReadData, group.nfriends, cod);
group.finmoney := 0;
FOR j:=1 TO group.nfriends DO BEGIN
group.friends[j] := ReadData;
END;
END;
GreedyGivers(group, npeople, strnames);
WRITELN(OUTPUT);
END;
>IF (group[posperson].inimoney <> 0) THEN
>giftmoney := group[posperson].inimoney DIV group[posperson].nfriends;
What about division by zero?
Input:
2
one two
one 100 0
two 10 1 one
can anyone plz tell me what is wrong with this code.. It works on the input provided.. Please let me know.... Thx in advance
[cpp]/* @JUDGE_ID: xxxxxxx 119 C++ "No special algo:)" */
# include<iostream.h>
# include<string.h>
char a[100][150];
int money[100],cash;
int n,i;
char name[200];
int people,j,k;