Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Monday, July 31, 2017

Evaluate the x + a = b


Code:

import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
 {
public static void main (String[] args)
{
Scanner ab=new Scanner(System.in);
int t=ab.nextInt();
while(t-->0)
{
   String temep=new String(ab.next());
   String str;
   if(temep.length()<4)
    str=new String(ab.nextLine());
   else
    str=new String(temep);
  // System.out.println(str);
   int a[]=new int[2];
   int j=0;
   char arr[]=str.toCharArray();
 
   for(int i=0;i<str.length();i++)
   {
       if(arr[i]>='0' && arr[i]<='9')
       {
          // System.out.println(arr[i]);
           int temp=arr[i]-'0';
           i++;
           while(i<str.length() && arr[i]>='0' && arr[i]<='9')
           {
             //  System.out.println(arr[1]);
               temp=temp*10+arr[i]-'0';
               i++;
           }
           a[j++]=temp;
       }
   }
   System.out.println(a[1]-a[0]);
}
}
}

0 Comments:

Post a Comment

Stats