I have tried many times. I coded in Java. It is running perfectly on my compiler. I don’t know what is the problem. It isn’t even passing a single test case. Please help. I believe there is some mistake in input scanning. The link of the problem is here: http://www.spoj.com/problems/ANARC08B/
Forgive me if anything is done in wrong format. I’m using the discussion panel for the first time.
It requires an Additional enter to terminate
Here is my code
import java.util.;
import java.io.;
import java.lang.;
import java.math.;
class Adding{
// Digit ki string
static String Strn(int n){
if(n==0)
return “063”;
else if(n==1)
return “010”;
else if(n==2)
return “093”;
else if(n==3)
return “079”;
else if(n==4)
return “106”;
else if(n==5)
return “103”;
else if(n==6)
return “119”;
else if(n==7)
return “011”;
else if(n==8)
return “127”;
else if(n==9)
return “111”;
return “”;
}
// Number se uski string
static String toStr(int n){
String s = "";
int d1=0;
while(n!=0){
d1 = n%10;
// Har digit ki string pta kar rha hun Strn se
s = Strn(d1) + s;
n = n/10;
}
return s;
}
// 3 length ki se digit pta kar rha hun
static int integ(String s){
if(s.equals("063"))
return 0;
else if(s.equals("010"))
return 1;
else if(s.equals("093"))
return 2;
else if(s.equals("079"))
return 3;
else if(s.equals("106"))
return 4;
else if(s.equals("103"))
return 5;
else if(s.equals("119"))
return 6;
else if(s.equals("011"))
return 7;
else if(s.equals("127"))
return 8;
else if(s.equals("111"))
return 9;
return 0;
}
// string se no pta kar rha hun;
static int number(String str){
int t = str.length();
int num = 0,n=0;
for(int i=0;i<t;){
String a = str.substring(i,i+3);
num=integ(a);
if(i==0)
n=num;
else
n=10*n+num;
i=i+3;
}
return n;
}
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
boolean bool = true;
String st = "";
st = scan.nextLine();
StringBuilder str = new StringBuilder();
while(!st.startsWith("BYE")){
int k = st.length();
st = st.substring(0,k-1);
String s1[] = st.split("\\+");
String a = s1[0];
String b = s1[1];
int x=number(a);
int y=number(b);
int z=x+y;
String c = a + "+" + b + "=";
c = c + toStr(z);
System.out.println(c);
st = scan.nextLine();
}
}
}