Skip to content

Commit 051cd40

Browse files
AccurateLee
1 parent 21d350c commit 051cd40

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

1369/B/Main.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.Scanner;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
7+
int t = sc.nextInt();
8+
for (int tc = 0; tc < t; ++tc) {
9+
sc.nextInt();
10+
String s = sc.next();
11+
12+
System.out.println(solve(s));
13+
}
14+
15+
sc.close();
16+
}
17+
18+
static String solve(String s) {
19+
int beginIndex = -1;
20+
while (beginIndex + 1 != s.length() && s.charAt(beginIndex + 1) == '0') {
21+
++beginIndex;
22+
}
23+
24+
int endIndex = s.length();
25+
while (endIndex != 0 && s.charAt(endIndex - 1) == '1') {
26+
--endIndex;
27+
}
28+
29+
return String.format("%s%s%s", s.substring(0, beginIndex + 1), (beginIndex + 1 == endIndex) ? "" : "0",
30+
s.substring(endIndex));
31+
}
32+
}

0 commit comments

Comments
 (0)