NYOJ Binary Conversion 244

Source: Internet
Author: User
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));}}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.