You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
835 B

#include <bits/stdc++.h>
using namespace std;
string zshiliu(int u) {
char q, p;
string s = "";
if (u / 16 >= 10)
p = 'A' + u / 16 - 10;
else
p = '0' + u / 16;
s += p;
if (u % 16 >= 10)
q = 'A' + u % 16 - 10;
else
q = '0' + u % 16;
s += q;
return s;
}
int zshi(string s) {
int a = 0;
if (s[0] >= 'A' && s[0] <= 'F')
a = (s[0] - 'A' + 10) * 16;
else if (s[0] >= '0' && s[0] <= '9')
a = (s[0] - '0') * 16;
int b = 0;
if (s[1] >= 'A' && s[1] <= 'F')
b = (s[1] - 'A' + 10);
else if (s[1] >= '0' && s[1] <= '9')
b = (s[1] - '0');
return a + b;
}
int main() {
cout << zshiliu(10) << endl;
cout << zshi("FF") << endl;
cout << zshi("AA") << endl;
return 0;
}