标签:[] har toc 代码实现 next line can pow substring
java API有现成的函数,可以使用,下面用代码实现。
【AC代码】
1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(String[] args) { 5 Scanner sc = new Scanner(System.in); 6 while (sc.hasNext()) { 7 String str = sc.nextLine(); 8 String str1 = str.substring(2); 9 char[] ch = str1.toCharArray(); 10 int n = ch.length; 11 int res = 0; 12 String ans; 13 for (int i = 0; i < ch.length; i++) { 14 if (ch[i] >= ‘A‘ && ch[i] <= ‘F‘) { 15 res += ((ch[i] - 55) * Math.pow(16, n - 1)); 16 n -= 1; 17 } 18 if (ch[i] >= ‘0‘ && ch[i] <= ‘9‘) { 19 res += ((ch[i] - 48) * Math.pow(16, n - 1)); 20 n -= 1; 21 } 22 } 23 ans = String.valueOf(res); 24 System.out.println(ans); 25 } 26 } 27 }
标签:[] har toc 代码实现 next line can pow substring
原文地址:http://www.cnblogs.com/StoneLuo/p/7467961.html