-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindTheWinner.java
52 lines (39 loc) · 1.32 KB
/
FindTheWinner.java
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
import java.util.Scanner;
public class FindTheWinner{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int noAndrea = in.nextInt();
int[] andrea = new int[noAndrea];
for(int i =0; i<noAndrea; i++) {
andrea[i] = in.nextInt();
}
int noMaria = in.nextInt();
int[] maria = new int[noMaria];
for(int i =0; i<noMaria; i++) {
maria[i] = in.nextInt();
}
String strGameType = in.next().toLowerCase();
String gameWinner = winner(andrea, maria, strGameType);
System.out.println(gameWinner);
}
static String winner(int[] andrea, int[] maria, String s) {
String winner = "";
int scroreAndrea = 0;
int scoreMaria = 0;
int index = 0;
if(s.equals("odd")) {
index = 1;
}
while (index < andrea.length && index < maria.length) {
scroreAndrea += andrea[index] - maria[index];
scoreMaria += maria[index] - andrea[index];
index+=2;
}
if(scroreAndrea == scoreMaria) {
winner = "Tie";
} else {
winner = scroreAndrea > scoreMaria? "Andrea":"Maria";
}
return winner;
}
}