这道题让把一个十六进制数转成十进制数。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<char> v = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
int main()
{
string s;
while(cin >> s){
reverse(s.begin(), s.end());
int p = 0;
int res = 0;
for(int i = 0; i < s.size()-2; ++i){
res += pow(16, i) * (find(v.begin(), v.end(), s[i]) - v.begin());
}
cout << res << endl;
}
}
还有一个神tm写法:
#include <iostream>
using namespace std;
int main()
{
int a;
while(cin>>hex>>a){
cout<<a<<endl;
}
}