16 hexadecimal simple operation time limit: 1000 MS | memory limit: 65535 KB difficulty: 1
-
Description
-
Now we will give you a hexadecimal addition and subtraction expression, which requires that the result of the expression be output in octal.
-
Input
-
Enter a positive integer T (0 <T <100000) in the first line)
Next there are T rows. Each line inputs a string s (length less than 15) which contains two numbers and a plus sign or a minus sign. The expression is valid and the number of all operations is less than 31 characters.
-
Output
-
Each expression outputs a row and outputs the result of an octal expression.
-
Sample Input
-
329+482318be+67844ae1-3d6c
-
Sample output
-
441141001026565
import java.util.Scanner;public class Main1 {public static void main(String[] args) {Scanner input = new Scanner(System.in);int t = input.nextInt();while(t-->0){String n = input.next();for(int i=0; i<n.length(); i++){if(n.charAt(i) == '+'){String []str = n.split("[+]");String a = Integer.valueOf(str[0],16).toString();int inta = Integer.valueOf(a);String b = Integer.valueOf(str[1],16).toString();int intb = Integer.valueOf(b);System.out.println(Integer.toOctalString(inta+intb));}else if(n.charAt(i) == '-'){String []str1 = n.split("[-]");String a = Integer.valueOf(str1[0],16).toString();int inta = Integer.valueOf(a);String b = Integer.valueOf(str1[1],16).toString();int intb = Integer.valueOf(b);System.out.println(Integer.toOctalString(inta-intb));}}}}}