Re: 119 Why WA??
Posted: Fri Jun 13, 2014 9:28 am
Whatever compiler the default is in XCode 5.1.
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
Code: Select all
laura 0 2 amr vick
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?
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;
}
Don't print blank line after last caseThe output for each group should be separated from other groups by a blank line
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]);
}
}
}
}
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;
}