String longString
(int len,
char one,
char two
) { for(int i = 0; i < len; ++i) {
if(i % 2 == 0) s += one;
else s += two;
}
return s;
}
public String[] findAny
(int N
) { // create last N-2 strings, each with one letter 'e'-'z'
for(int i = 2; i < N; ++i) {
if(i == 2 || ans[i-1].equals("z"))
ans[i] = "e";
else {
ans[i] = "";
ans[i] += (char) (ans[i - 1].charAt(0) + 1);
}
}
int already = 0;
for(int i = 2; i < N; ++i)
for(int j = i + 1; j < N; ++j)
if(ans[i].charAt(0) == ans[j].charAt(0))
++already;
ans[0] = longString(min(100, 1 + already), 'a', 'b');
already -= ans[0].length() - 1;
ans[1] = longString(1 + already, 'c', 'd');
return ans;
}
U3RyaW5nIGxvbmdTdHJpbmcoaW50IGxlbiwgY2hhciBvbmUsIGNoYXIgdHdvKSB7CglTdHJpbmcgcyA9ICIiOwoJZm9yKGludCBpID0gMDsgaSA8IGxlbjsgKytpKSB7CgkJaWYoaSAlIDIgPT0gMCkgcyArPSBvbmU7CgkJZWxzZSBzICs9IHR3bzsKCX0KCXJldHVybiBzOwp9CnB1YmxpYyBTdHJpbmdbXSBmaW5kQW55KGludCBOKSB7CglTdHJpbmdbXSBhbnMgPSBuZXcgU3RyaW5nW05dOwoJLy8gY3JlYXRlIGxhc3QgTi0yIHN0cmluZ3MsIGVhY2ggd2l0aCBvbmUgbGV0dGVyICdlJy0neicKCWZvcihpbnQgaSA9IDI7IGkgPCBOOyArK2kpIHsKCQlpZihpID09IDIgfHwgYW5zW2ktMV0uZXF1YWxzKCJ6IikpCgkJCQlhbnNbaV0gPSAiZSI7CgkJZWxzZSB7CgkJCWFuc1tpXSA9ICIiOwoJCQlhbnNbaV0gKz0gKGNoYXIpIChhbnNbaSAtIDFdLmNoYXJBdCgwKSArIDEpOwoJCX0KCX0KCWludCBhbHJlYWR5ID0gMDsKCWZvcihpbnQgaSA9IDI7IGkgPCBOOyArK2kpCgkJZm9yKGludCBqID0gaSArIDE7IGogPCBOOyArK2opCgkJCWlmKGFuc1tpXS5jaGFyQXQoMCkgPT0gYW5zW2pdLmNoYXJBdCgwKSkKCQkJCSsrYWxyZWFkeTsKCWFuc1swXSA9IGxvbmdTdHJpbmcobWluKDEwMCwgMSArIGFscmVhZHkpLCAnYScsICdiJyk7CglhbHJlYWR5IC09IGFuc1swXS5sZW5ndGgoKSAtIDE7CglhbnNbMV0gPSBsb25nU3RyaW5nKDEgKyBhbHJlYWR5LCAnYycsICdkJyk7CglyZXR1cm4gYW5zOwp9
Main.java:1: error: class, interface, or enum expected
String longString(int len, char one, char two) {
^
Main.java:3: error: class, interface, or enum expected
for(int i = 0; i < len; ++i) {
^
Main.java:3: error: class, interface, or enum expected
for(int i = 0; i < len; ++i) {
^
Main.java:3: error: class, interface, or enum expected
for(int i = 0; i < len; ++i) {
^
Main.java:5: error: class, interface, or enum expected
else s += two;
^
Main.java:6: error: class, interface, or enum expected
}
^
Main.java:8: error: class, interface, or enum expected
}
^
Main.java:9: error: class, interface, or enum expected
public String[] findAny(int N) {
^
Main.java:12: error: class, interface, or enum expected
for(int i = 2; i < N; ++i) {
^
Main.java:12: error: class, interface, or enum expected
for(int i = 2; i < N; ++i) {
^
Main.java:12: error: class, interface, or enum expected
for(int i = 2; i < N; ++i) {
^
Main.java:15: error: class, interface, or enum expected
else {
^
Main.java:17: error: class, interface, or enum expected
ans[i] += (char) (ans[i - 1].charAt(0) + 1);
^
Main.java:18: error: class, interface, or enum expected
}
^
Main.java:21: error: class, interface, or enum expected
for(int i = 2; i < N; ++i)
^
Main.java:21: error: class, interface, or enum expected
for(int i = 2; i < N; ++i)
^
Main.java:21: error: class, interface, or enum expected
for(int i = 2; i < N; ++i)
^
Main.java:22: error: class, interface, or enum expected
for(int j = i + 1; j < N; ++j)
^
Main.java:22: error: class, interface, or enum expected
for(int j = i + 1; j < N; ++j)
^
Main.java:25: error: class, interface, or enum expected
ans[0] = longString(min(100, 1 + already), 'a', 'b');
^
Main.java:26: error: class, interface, or enum expected
already -= ans[0].length() - 1;
^
Main.java:27: error: class, interface, or enum expected
ans[1] = longString(1 + already, 'c', 'd');
^
Main.java:28: error: class, interface, or enum expected
return ans;
^
Main.java:29: error: class, interface, or enum expected
}
^
24 errors