看了之前的讨论,测试点
2
R228C494
R98C702
我输出的是
RZ228
ZZ98
好像是对的吧?
代码:
#include <iostream>
#include <cstring>
#include <stack>
int n;
std:: string s;
std:: stack<int> t;
inline bool check()
{
if (s[0] != 'R') return false;
else if (s[1] < '0' || s[1] > '9') return false;
else
{
for (int i = 2; i < s.size(); ++i)
if (s[i] == 'C') return true;
return true;
}
}
int main()
{
std:: cin >> n;
for (int i = 1; i <= n; ++i)
{
std :: cin >> s;
if (check())
{
int i = 1, r = 0, c = 0;
for (; s[i] >= '0' && s[i] <= '9'; ++i) r = (r << 3) + (r << 1) + (s[i] ^ 48);
for (++i; s[i] >= '0' && s[i] <= '9'; ++i) c = (c << 3) + (c << 1) + (s[i] ^ 48);
for (; c; c = (c + 25) / 26 - 1) t.push((c - 1) % 26 + 1);
for (; !t.empty(); t.pop()) printf("%c", t.top() + 64);
printf("%d\n", r);
}
else
{
int i = 0, r = 0, c = 0;
for (; s[i] >= 'A' && s[i] <= 'Z'; ++i) c = (c << 4) + (c << 3) + (c << 1) + (s[i] - 64);
for (; s[i] >= '0' && s[i] <= '9'; ++i) r = (r << 3) + (r << 1) + (s[i] ^ 48);
printf("R%dC%d\n", r, c);
}
}
return 0;
}