119 - Greedy Gift Givers
Moderator: Board moderators
Re: 119 Why WA??
Whatever compiler the default is in XCode 5.1.
Re: 119 Why WA??
when money given to 0 it becomes 0?gtcoder wrote:
InputOutputCode: Select all
2 Fat Dude Fat 1000 0 Dude 100 1 Fat
3. Print a blank line after each case except the last one.Code: Select all
Fat 100 Dude -100
what happens 0 given to anyone?
Code: Select all
laura 0 2 amr vick
Last edited by Blief.S on Fri Jun 27, 2014 12:34 pm, edited 1 time in total.
Re: 119 Why WA??
I'm afraid I don't understand this question, but see if the comments below help.Blief.S wrote:when money given to 0 it becomes 0?
If 0 money is given (as with laura in the sample), that 0 is divided by the number of people to give gifts to, and that result is added to the "net worth" of those people. Just as with any other amount. If you carefully analyze the first sample from the problem statement, you can clearly see what is the result of laura giving away 0 to two friends.Blief.S wrote:what happens 0 given to anyone?
I think the problem statement is failry clear, so when in doubt, take the time to patiently read it as many times as necessary until you understand all the details.
Re: 119 Why WA??
Last edited by Blief.S on Sun Jun 29, 2014 5:04 pm, edited 2 times in total.
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
119 - Keep getting WA even though i test many many times
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
using namespace std;
typedef vector<string> vs;
int indexP(vs& a, string s)
{
for(int i =0; i < a.size(); i++)
{
if(a[i] == s)
return i;
}
return -1;
}
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
freopen("input.txt", "r", stdin);
int n;
//cout << "enter amount person" << endl;
while(cin >> n)
{
cin.ignore();
vs name;
string temp, owner, gifter;
int money[n], cash, amt;
//cout << "enter: " << endl;
for(int i = 0; i < n; i++)
{
cin >> temp;
name.push_back(temp);
money[i] = 0;
}
for(int i = 0; i < n; i++)
{
cin >> owner;
int index = indexP(name, owner);
cin >> cash;
cin >> amt;
cin.ignore();
int received, leftover;
if(amt != 0){
leftover = cash%amt;
//cout << money[index] << endl;
money[index] = (money[index] - cash + leftover);
received = cash/amt;
while(amt--)
{
cin >> gifter;
index = indexP(name, gifter);
money[index] += received;
}
}
}
for(int i = 0; i < n; i++)
{
cout << name[i] << " " << money[i] << endl;
}
cout << "\n";
}
return 0;
}
Re: 119 - Keep getting WA even though i test many many times
Post in existing thread. Use search by problem number (119). Don't read from file or post here code that you actually submit. Problem description says
Don't print blank line after last caseThe output for each group should be separated from other groups by a blank line
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 119 - Keep getting WA even though i test many many times
I'm sorry for posting into a new thread. But you solved my problem. Thanks a alot.
119-Greedy Gift Givers
Hi I am getting wrong answer from the following code and not able to trace error.Could you help me ?
Code: Select all
import java.util.Scanner;
import java.util.HashMap;
class Main{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (true) {
int n = 0;
try {
n = sc.nextInt();
} catch (Exception e) {
break;
}
String[] friends =new String[n];
HashMap<String,Integer> map=new HashMap<String,Integer>();
for(int i=0;i<n;i++)
{
friends[i]=sc.next();
map.put(friends[i], i);
}
int []money=new int[n];
for(int i=0;i<n;i++)
{
int idx = map.get(sc.next());
int gift = sc.nextInt();
int M = sc.nextInt();
if (M!= 0) {
int rem =gift%M;
int dev=gift/M;
money[idx]+=rem-gift;
for(int j=0;j<M;j++)
{
money[map.get(sc.next())]+=dev;
}
}
}
for(int j=0;j<n;j++)
{
System.out.println(friends[j] + " " + money[j]);
}
}
}
}
Re: 119-Greedy Gift Givers
Read the problem statement carefully.
The output for each group should be separated from other groups by a blank line.
The output for each group should be separated from other groups by a blank line.
-
- New poster
- Posts: 1
- Joined: Mon Sep 14, 2015 10:03 pm
Re: 119 - Greedy Gift Givers
Please tell me why this code is getting WA?
EDIT: Problem solved. Thank You
Code: Select all
#include <stdio.h>
#include <string.h>
int main ()
{
long np, i, money, person, divide, c, flag = 0;
char giver [20], receiver [20];
while (scanf ("%ld", &np) != EOF) {
struct friends {
int spend;
int receive;
char name [20];
} A [12] = {0, 0, 0};
for (i = 0; i < np; i++)
scanf ("%s", A [i].name);
for (c = 0; c < np; c++ ) {
scanf ("%s", giver);
scanf ("%ld", &money);
i = 0;
while (strcmp (A [i].name, giver) != 0)
i++;
A [i].spend += money;
scanf ("%ld", &person);
if (person == 0) {
A [i].receive += money;
continue;
}
divide = person;
A [i].receive += money - ((money / person) * person);
while (person--) {
scanf ("%s", receiver);
i = 0;
while (strcmp (A [i].name, receiver) != 0)
i++;
A [i].receive += (money / divide);
}
}
if (flag == 1)
printf("\n");
flag = 1;
for (i = 0; i < np; i++)
printf("%s %ld\n", A [i].name, A [i].receive - A [i].spend);
}
return 0;
}