用unsigned前:RE
用unsigned后:WA
第一个点和第三个点过不去(没想到有一天能被红题卡这么痛苦
代码:(码风和思路轻喷 我是lj)
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
string sixt[16] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
string s = "0x", a;
ll x;
void stolg(string a) {
int cnt = -1;
for(int i = a.size() - 1; i >= 0; --i) x += (a[i] - '0') * pow(10, ++cnt);
}
int main() {
char ch;
while(1) {
cin >> ch;
if(ch == '{') {cout << ch; continue; }
if(ch >= '0' && ch <= '9') a += ch;
if(ch == ',') {
stolg(a);
string as = "";
while(x != 0) as += sixt[x % 16], x /= 16;
for(int i = as.size() - 1; i >= 0; --i) s += as[i];
if(s.size() <= a.size()) cout << s;
else cout << a;
cout << ',';
s = "0x", a = "", x = 0;
}
if(ch == '}') {
stolg(a);
string as = "";
while(x != 0) as += sixt[x % 16], x /= 16;
for(int i = as.size() - 1; i >= 0; --i) s += as[i];
if(s.size() <= a.size()) cout << s;
else cout << a;
cout << ch << endl;
return 0;
}
}
return 0;
}