This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgift1.java
More file actions
73 lines (66 loc) · 1.53 KB
/
gift1.java
File metadata and controls
73 lines (66 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
ID: johnath6
LANG: JAVA
TASK: gift1
PROG: gift1
*/
import java.io.*;
import java.util.*;
public class gift1 {
public static int cache;
public static int geteach(int what,int divide) {
try {
cache=what%divide;
return (what-cache)/divide;
}catch(ArithmeticException e){
cache=0;
return 0;
}
}
public static int lsearch(Object[] j,Object k) {
for(int i=0;i<j.length;i++) {
if(j[i].equals(k)) {
return i;
}
}
return -1;
}
public static void main(String[] args) throws IOException{
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("gift1.out")));
BufferedReader f=new BufferedReader(new FileReader("gift1.in"));
int NP=Integer.parseInt(f.readLine());
String[] names;
int[] money;
names=new String[NP];
money=new int[NP];
for(int i=0;i<NP;i++) {
names[i]=f.readLine();
money[i]=0;
}
String person;
StringTokenizer st;
int share,people,deduct,each,p;
for(int i=0;i<NP;i++) {
person=f.readLine();
st=new StringTokenizer(f.readLine());
share=Integer.parseInt(st.nextToken());
deduct=-share;
people=Integer.parseInt(st.nextToken());
each=geteach(share,people);
deduct=deduct+cache;
cache=0;
for(int j=0;j<people;j++) {
p=lsearch(names,f.readLine());
money[p]=money[p]+each;
}
p=lsearch(names,person);
money[p]=money[p]+deduct;
}
for(int i=0;i<NP;i++) {
out.print(names[i]+" ");
out.println(money[i]);
}
f.close();
out.close();
}
}