蒟蒻求助!WA了,自己测得样例都过了
查看原帖
蒟蒻求助!WA了,自己测得样例都过了
592476
sz_jinzikai楼主2023/2/24 20:27

//洛谷CF1B

# include <bits/stdc++.h>

# define ffor(i,name) \
	for (auto i = name.end (); i != name.end (); i ++)

# define iter(type) \
	type :: iterator

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

int n, power, sum, i, j, m, ans, t;

string a;

bool judge () {

	while (i < m && a[i] > '9')
		i ++;

	j = i;

	while (i < m && a[i] < 'A')
		i ++;

	return i > m - 2;

}

void print (int x) {

	if (x > 26)
		print (x / 26);

	if (x % 26)
		cout << (char) (x % 26 - 1 + 'A');
	else
		cout << 'Z';

	return ;

}

int main () {

	ios::sync_with_stdio (0);

	cin.tie (0);

	cout.tie (0);

	cin >> n;

	while (n --) {

		cin >> a;

		m = a.size ();

		ans = 0;

		if (judge ()) {

			power = 1;

			for (i = j - 2; i >= 0; i --)
				ans += (a[i] - 'A' + 1) * power, power *= 26;

			cout << 'R';

			for (i = j - 1; i < m; i ++)
				cout << a[i];

			cout << 'C' << ans;

		} else {

			while (a[j] < 'C')
				j ++;

			for (i = j + 1; i < m; i ++)
				ans = ans * 10 + a[i] - '0';
//			cout << ans << '\n';
			print (ans);

			for (i = 1; i < j; i ++)
				cout << a[i];

		}

		cout << '\n';

	}

	return 0;

}
2023/2/24 20:27
加载中...