answersLogoWhite

0

/*

ID: isurube1

LANG: JAVA

TASK: gift1

*/

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

public class gift1 {

public static void main(String[] args) {

try{

BufferedReader fileIn = new BufferedReader(new FileReader("gift1.in"));

PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter("gift1.out")));

try{

int quantity = Integer.parseInt(fileIn.readLine());

String[][] outFile = new String [quantity][2];

for (int i = 0; i < quantity; i++) {

outFile [i][0] = fileIn.readLine();

outFile [i][1] = "0";

}

for (int i = 1; i <= quantity; i++) {

String giver = fileIn.readLine();

String temp = fileIn.readLine();

int money = Integer.parseInt(temp.split(" ")[0]);

int receivers = Integer.parseInt(temp.split(" ")[1]);

int giversValue = 0;

if (money != 0 receivers != 0){

giversValue = (money % receivers) - money;

}

for (int j = 0; j < outFile.length; j++) {

if (outFile[j][0].equals(giver)){

outFile[j][1] = Integer.toString(giversValue + Integer.parseInt(outFile[j][1]));

break;

}

}

if(receivers != 0){

money /= receivers;

for (int j = 1; j <= receivers; j++) {

temp = fileIn.readLine();

for (int k = 0; k < outFile.length; k++) {

if (outFile[k][0].equals(temp)){

outFile[k][1] = Integer.toString(money + Integer.parseInt(outFile[k][1]));

break;

}

}

}

}

}

for (int i = 0; i < outFile.length; i++) {

fileOut.write(outFile[i][0] + " " +outFile[i][1]+"\n");

}

} finally {

fileIn.close();

fileOut.close();

}

} catch (IOException e) {

throw new RuntimeException(e);

}

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

In the giver what is the givers extra gift?

The memory of music.


What are Spain gift giver?

What are the Spain gifts givers


What are the release dates for The Gift of All A Community of Givers - 2008?

The Gift of All A Community of Givers - 2008 was released on: USA: 8 November 2008 (Grand Rapids, Michigan)


By what title were the the three wise men known?

as the gift givers to jesus


What made these two gift givers the wisest from the gift of the magi?

The two gift givers in &quot;The Gift of the Magi&quot; were considered the wisest because they sacrificed their most prized possessions for each other, showing selflessness and love. Their actions demonstrated true understanding of the meaning of giving and receiving.


When was The Gift That Keeps Giving created?

The Gift That Keeps Giving was created on 2007-12-25.


Does Kwanzaa have any gift givers?

well, during Kwanzaa, the adults/elders give gifts to the children.


Why do your stores not accept Subway gift cards?

The Black Ones. Their Greedy!


Who is the gift bringer in Brazil?

There are two gift givers in Brazil for Christmas. One is Papai Noel who is Father Christmas. The other is Bom Velhinho who is the Good Old Man.


Are Della and Jim the wisest gift givers?

Yes, Della and Jim are wise gift givers because they both sacrificed their most treasured possessions to purchase gifts for each other that held great sentimental value and symbolized their love and appreciation. Their gifts were thoughtful and selfless, embodying the true spirit of giving.


Father's Day Gift Baskets: Perfect for Dad and Your Budget ?

Gift baskets make great gifts because a number of items are combined in an attractive package. Creating homemade Father's Day gift baskets allows gift givers to personalize gifts for dads, grandparents or other recipients. These gifts can also be created in ways that suit gift givers' budgets. Gathering a number of small items to fill baskets can be less expensive than splurging on one large item. Purchasing items over time allows gift givers to take advantage of sales and discounts and allows givers to spend small amounts over time rather than large lump sums. Father's Day gift baskets can be created by using a basket or other container to hold several small items. Selecting a theme for the gifts to be included in the basket makes the gift basket into one cohesive gift. Some popular themes are movie night, sports or foods. Personalizing Father's Day gift baskets for their recipients by filling baskets with items related to their favorite things or activities creates gifts that let the recipients know they are truly appreciated. Gift baskets can give big without requiring givers to spend big.


What is the gift giver if Bethlehem called?

The gift givers in Betlehem were known as Magi, they were the star gazers of the time; Astrologists, Alchemists, perhaps, etc. They were not kings and there were probably more than three.