Skip to content

Commit 6e15f86

Browse files
committed
fix(p2190A): correct edge case logic and handle trailing whitespace
1 parent b2fd509 commit 6e15f86

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

src/main/java/com/lzw/solutions/codeforces/p2190A/Main.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ void solve() throws IOException {
2424
int t = Integer.parseInt(in.readLine());
2525
while (t-- > 0) {
2626
int n = Integer.parseInt(in.readLine());
27-
String s = in.readLine();
28-
assert (s.length() == n);
27+
String s = in.readLine().trim();
2928
int i;
3029
int zero = 0, one = 0;
3130
for (i = 0; i < n; i++) {
@@ -38,7 +37,6 @@ void solve() throws IOException {
3837
if (zero == n || one == n) {
3938
out.println("Bob");
4039
} else {
41-
out.println("Alice");
4240
ArrayList<Integer> positions = new ArrayList<>();
4341
for (i = 0; i < n; i++) {
4442
char target;
@@ -51,15 +49,20 @@ void solve() throws IOException {
5149
positions.add(i);
5250
}
5351
}
54-
int size = positions.size();
55-
out.println(size);
56-
for (i = 0; i < size; i++) {
57-
if (i != 0) {
58-
out.print(' ');
52+
if (positions.size() == 0) {
53+
out.print("Bob");
54+
} else {
55+
out.println("Alice");
56+
int size = positions.size();
57+
out.println(size);
58+
for (i = 0; i < size; i++) {
59+
if (i != 0) {
60+
out.print(' ');
61+
}
62+
out.print(positions.get(i) + 1);
5963
}
60-
out.print(positions.get(i) + 1);
64+
out.println();
6165
}
62-
out.println();
6366
}
6467
}
6568
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.lzw.solutions.codeforces.p2190A;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.io.PrintWriter;
7+
8+
public class MainPlus {
9+
10+
BufferedReader in;
11+
PrintWriter out;
12+
13+
MainPlus() {
14+
in = new BufferedReader(new InputStreamReader(System.in));
15+
out = new PrintWriter(System.out);
16+
}
17+
18+
// 100100 100101 10 01 100 101 101010
19+
// 000011(1456) 000111(145) 01 01 001 011 000111(1346)
20+
21+
void solve() throws IOException {
22+
int t = Integer.parseInt(in.readLine());
23+
while (t-- > 0) {
24+
int n = Integer.parseInt(in.readLine());
25+
String s = in.readLine();
26+
out.println("Alice");
27+
}
28+
}
29+
30+
void close() throws IOException {
31+
if (in != null) {
32+
in.close();
33+
}
34+
if (out != null) {
35+
out.flush();
36+
out.close();
37+
}
38+
}
39+
40+
public static void main(String[] args) throws Exception {
41+
MainPlus main = new MainPlus();
42+
main.solve();
43+
main.close();
44+
}
45+
}

src/main/resources/codeforces/p2190A/1.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
000
44
2
55
10
6-
3
7-
101
6+
6
7+
101010

0 commit comments

Comments
 (0)