Skip to content

Commit 0bfb382

Browse files
committed
Add sevenwonders.java
1 parent 6f1fc32 commit 0bfb382

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Related settings from `settings.json`:
161161
| [reversebinary](https://open.kattis.com/problems/reversebinary) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/reversebinary/reversebinary.cpp), [java](https://github.com/dbarenholz/kattis/blob/main/src/reversebinary/reversebinary.java) |
162162
| [rijeci](https://open.kattis.com/problems/rijeci) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/rijeci/rijeci.cpp) |
163163
| [romans](https://open.kattis.com/problems/romans) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/romans/romans.cpp) |
164-
| [sevenwonders](https://open.kattis.com/problems/sevenwonders) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/sevenwonders/sevenwonders.cpp) |
164+
| [sevenwonders](https://open.kattis.com/problems/sevenwonders) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/sevenwonders/sevenwonders.cpp), [java](https://github.com/dbarenholz/kattis/blob/main/src/sevenwonders/sevenwonders.java) |
165165
| [shatteredcake](https://open.kattis.com/problems/shatteredcake) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/shatteredcake/shatteredcake.cpp) |
166166
| [sibice](https://open.kattis.com/problems/sibice) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/sibice/sibice.cpp) |
167167
| [sifferprodukt](https://open.kattis.com/problems/sifferprodukt) | [cpp](https://github.com/dbarenholz/kattis/blob/main/src/sifferprodukt/sifferprodukt.cpp) |

src/sevenwonders/sevenwonders.java

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package sevenwonders;
2+
3+
import java.io.BufferedReader;
4+
import java.io.BufferedWriter;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.io.OutputStreamWriter;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.NoSuchElementException;
11+
import java.util.StringTokenizer;
12+
13+
class sevenwonders {
14+
private void run() throws IOException {
15+
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
16+
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
17+
18+
String word = r.readLine();
19+
r.close();
20+
21+
Map<Character, Integer> nC = new HashMap<>();
22+
for (int i = 0; i < word.length(); i++) {
23+
char c = word.charAt(i);
24+
if (!nC.containsKey(c))
25+
nC.put(c, 1);
26+
else
27+
nC.put(c, nC.get(c) + 1);
28+
}
29+
30+
String str = nC.toString()
31+
.replace("{", "")
32+
.replace(",", "")
33+
.replace("}", "")
34+
.replace("}", "")
35+
.replace("C", "")
36+
.replace("T", "")
37+
.replace("G", "")
38+
.replace("=", "");
39+
40+
StringTokenizer s = new StringTokenizer(str);
41+
int c, t, g;
42+
43+
try {
44+
c = Integer.parseInt(s.nextToken());
45+
} catch (NoSuchElementException e) {
46+
c = 0;
47+
}
48+
try {
49+
t = Integer.parseInt(s.nextToken());
50+
} catch (NoSuchElementException e) {
51+
t = 0;
52+
}
53+
try {
54+
g = Integer.parseInt(s.nextToken());
55+
} catch (NoSuchElementException e) {
56+
g = 0;
57+
}
58+
59+
int v = (int) (Math.pow(c, 2) + Math.pow(t, 2) + Math.pow(g, 2));
60+
int a = Math.min(Math.min(c, t), g);
61+
62+
v += a * 7;
63+
64+
w.write(v + "\n");
65+
w.flush();
66+
}
67+
68+
public static void main(String[] a) throws IOException {
69+
(new sevenwonders()).run();
70+
}
71+
72+
}

0 commit comments

Comments
 (0)