I have submitted the code, the same code runs fine under my machine but it gives Test: #1, time: 124 ms., memory: 0 KB, exit code: 1, checker exit code: 0, verdict: RUNTIME_ERROR
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package algorithms;
import java.util.Scanner;
/**
*
* @author Naved Momin<[email protected]/[email protected]>
*/
public class SimpleMath {
class Node{
char data;
Node left, right;
}
String data,op = "";
Node root;
public void ALGO( ){
Scanner s = new Scanner(System.in);
data = s.nextLine();
if( checker() == -1 )
System.out.println( data );
else
{
mkTree();
traverseTreeInorder(root);
op = op.substring(0, op.length()-1);
System.out.println(op);
}
}
int checker( ){
return data.indexOf("+");
}
public static void main(String[] args) {
// TODO code application logic here
new SimpleMath().ALGO();
}
private void mkTree() {
char[] toCharArray = data.toCharArray();
for (char c : toCharArray) {
if( c != '+'){
tree( c );
}
}
}
private void traverseTreeInorder(Node r) {
if( r != null ){
traverseTreeInorder(r.left);
op = op + r.data + "+";
traverseTreeInorder(r.right);
}
}
private void tree(char c) {
if( root == null ){
root = new Node();
root.data = c;
}else{
Node r,p;
r = p = root;
int i,j;
i = (int)c;
while (r != null ) {
p = r;
j = (int)r.data;
if( i < j )
r = r.left;
else
r = r.right;
}
r = new Node();
r.data = c;
i = (int)r.data;
j = (int)p.data;
if( i < j )
p.left = r;
else
p.right = r;
}
}
}
hint: "package algorithms"
I've submitted your code without the line "package algorithms;" and got accepted. see: 4430084
thanks guys for the help