-
Notifications
You must be signed in to change notification settings - Fork 0
/
card-game.java
74 lines (62 loc) · 1.98 KB
/
card-game.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
public class ProgramJava {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String trumpSuit = sc.next();
String first = sc.next();
String second = sc.next();
int indFirst = 0;
int indSec = 0;
int firstContainTrampSuit = 0;
int secondContainTrampSuit = 0;
HashSet<Character> tramp = new HashSet<Character>(4);
tramp.add('S');
tramp.add('H');
tramp.add('D');
tramp.add('C');
char [] rank = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
for (int i = 0; i<rank.length; i++){
if (first.charAt(0) == rank[i]){
indFirst = i;
break;
}
}
for (int i = 0; i<rank.length; i++){
if (second.charAt(0) == rank[i]){
indSec = i;
break;
}
}
if (first.charAt(1) == trumpSuit.charAt(0)){
firstContainTrampSuit = 1;
}
if (second.charAt(1) == trumpSuit.charAt(0)){
secondContainTrampSuit = 1;
}
if (firstContainTrampSuit == 0 && secondContainTrampSuit == 0){
if (first.charAt(1) != second.charAt(1)){
System.out.println("NO");
}
else if (indFirst>indSec){
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
else if (firstContainTrampSuit == 1 && secondContainTrampSuit == 0){
System.out.println("YES");
}
else if (firstContainTrampSuit == 0 && secondContainTrampSuit == 1){
System.out.println("NO");
}
else if (firstContainTrampSuit == 1 && secondContainTrampSuit == 1){
if (indFirst>indSec){
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}