P8115 「RdOI R3.5」Table
签到题,先将字符串中的每个数字分离,然后转成 进制对比即可。但是我 分了很多次,因为要特判 。
数据比较大,最好开 __int128_t。
代码:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define int __uint128_t
vector<int> vec;
string ss;
string s;
string change(int x)
{
if (x == 0) return "0x0";
string k = "";
while (x)
{
int m = x % 16;
x /= 16;
if (m <= 9) k += m + '0';
else
{
k += (char)('A' + (m - 10));
}
}
reverse(k.begin(), k.end());
string l = "0x" + k;
return l;
}
string __128tostring(int x)
{
if (x == 0) return "0";
string p = "";
while (x)
{
p += x % 10 + '0';
x /= 10;
}
reverse(p.begin(), p.end());
return p;
}
signed main()
{
cin >> s;
int pre = -1, l = s.size() - 1;
for (int i = 0; i <= l; i++)
{
if (isdigit(s[i]))
{
if (pre == -1) pre = 0;
pre = pre * 10 + (s[i] - '0');
}
else
{
if (s[i] == '{' || pre == -1) continue;
vec.push_back(pre);
pre = -1;
}
}
for (int i = 0; i < vec.size(); i++)
{
string m = change(vec[i]);
string q = __128tostring(vec[i]);
if (m.size() <= q.size()) ss += m;
else ss += q;
ss += ",";
}
printf("{");
string ans = ss;
if (ans.size()) ans.pop_back();
cout << ans << "}\n";
return 0;
}

浙公网安备 33010602011771号