Topic description
Write a program that accepts a string of hexadecimal values and outputs a string of decimal values for that value. (Multiple groups are input at the same time)
Enter description:
Enter a numeric string in hexadecimal.
Output description:
Output a decimal string of this value.
Example 1
enter
0xA
output
10
#include<bits/stdc++.h> using namespace std; int sum = 0; void Zh(string s) { reverse(s.begin(),s.end()); int len = s.length(); sum = 0; for(int i=0;i<len-2;i++) { int t; if(s[i]>='A'&&s[i]<='A'+6) t = s[i]-'A'+10; else t = s[i]-'0'; //cout<<t<<endl; sum += pow(16,i)*t; } printf("%d\n",sum); } intmain() { string s; while(cin>>s) { Zh (s); } }