Hi there,
While submitting Java code for the problem - http://www.codechef.com/problems/NF03/, the NZEC is appearing. It seems that somewhere Exception is thrown. Could you help me finding the problem?
The code:
package magic.labs.algorithms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class ReverseStr {
public static void main(String[] args) {
System.out.println(result());
}
private static String result() {
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
String s = null;
try {
s = obj.readLine();
} catch (IOException e) {
;
}
if(s == null) {
return null;
}
char[] string = new char[s.length()];
for(int i=0;i<string.length;i++)
string[i] = s.charAt(i);
int b=0;
for(int i=0;i<string.length;i++) {
if ((string[i] < 'a' || string[i] > 'z') && (string[i] < 'A' || string[i] > 'Z') && (string[i] < '0' || string[i] > '9')) {
reverse(string,b,i);
b=i+1;
}
}
reverse(string,b,string.length);
StringBuilder str = new StringBuilder();
for(int i=0;i<string.length;i++) {
str.append(string[i]);
}
return str.toString();
}
private static void reverse(char[] s, int begin, int end) {
int len = end - begin;
for (int i = begin; i < begin + len / 2; i++) {
char t = s[i];
s[i] = s[begin + end - i - 1];
s[begin + end - i - 1] = t;
}
}
}
I’m sorry for clumsy code.
Thanks in advance.