NYOJ 進位轉換 244

來源:互聯網
上載者:User
16進位的簡單運算時間限制:1000 ms  |  記憶體限制:65535 KB難度:1
描述
現在給你一個16進位的加減法的運算式,要求用8進位輸出運算式的結果。

輸入
第一行輸入一個正整數T(0<T<100000)
接下來有T行,每行輸入一個字串s(長度小於15)字串中有兩個數和一個加號或者一個減號,且運算式合法並且所有運算的數都小於31位
輸出
每個運算式輸出佔一行,輸出運算式8進位的結果。
範例輸入
329+482318be+67844ae1-3d6c
範例輸出
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));}}}}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.