fork download
  1. String longString(int len, char one, char two) {
  2. String s = "";
  3. for(int i = 0; i < len; ++i) {
  4. if(i % 2 == 0) s += one;
  5. else s += two;
  6. }
  7. return s;
  8. }
  9. public String[] findAny(int N) {
  10. String[] ans = new String[N];
  11. // create last N-2 strings, each with one letter 'e'-'z'
  12. for(int i = 2; i < N; ++i) {
  13. if(i == 2 || ans[i-1].equals("z"))
  14. ans[i] = "e";
  15. else {
  16. ans[i] = "";
  17. ans[i] += (char) (ans[i - 1].charAt(0) + 1);
  18. }
  19. }
  20. int already = 0;
  21. for(int i = 2; i < N; ++i)
  22. for(int j = i + 1; j < N; ++j)
  23. if(ans[i].charAt(0) == ans[j].charAt(0))
  24. ++already;
  25. ans[0] = longString(min(100, 1 + already), 'a', 'b');
  26. already -= ans[0].length() - 1;
  27. ans[1] = longString(1 + already, 'c', 'd');
  28. return ans;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty