写出一个程序,接受一个十六进制的数值字符串,输出该数值的十进制字符串。(多组同时输入 )
Java代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String str = null;
Scanner in =new Scanner(System.in);
while(in.hasNext()){
str = in.nextLine();
int res=Integer.parseInt(str.substring(2, str.length()), 16);
System.out.println(res);
}
}
}
C++代码:
#include <iostream>
using namespace std;
int main()
{
int a;
while(cin>>hex>>a){
cout<<a<<endl;
}
return 0;
}