第六个点WA,求调
  • 板块CF1B Spreadsheets
  • 楼主sqrt404
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/2/29 21:38
  • 上次更新2024/3/1 11:17:42
查看原帖
第六个点WA,求调
637410
sqrt404楼主2024/2/29 21:38
#include <bits/stdc++.h>
using namespace std;
char c[] = {'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'};
bool isRC(string s)
{
	if(s[0] == 'R')
	{
		int sum = 0, R, C;
		for(int i = 1;;i++)
		{
			if(s[i] == 'C')
			{
				C = i;
				break;
			}
			if(s[i] > '9' || s[i] < '0') return false;
			sum++; 
		}
		if(sum == 0) return false;
		for(int i = C + 1; i < s.size(); i++) if(s[i] > '9' || s[i] < '0') return false;
		return true;
	}
	else return false;
}
string tento26(int num)
{
    string str = "";
    while(num > 0)
	{
        int gg = num % 26;
		str.insert(str.begin(), c[gg]);
        num /= 26;
    }
    return str;
}
int twenty6toten(string s)
{
	int num = 0, ts = 1;
	for(int i = s.size() - 1; i >= 0; i--)
	{
		num += (s[i] - 'A' + 1) * ts;
		ts *= 26;
	}
	return num;
}
int main()
{
	string s;
	int t;
	cin >> t;
	while(t--)
	{
		cin >> s;
		if(isRC(s))
		{
			int C;
			for(int i = 0;;i++)
			{
				if(s[i] == 'C')
				{
					C = i;
					break;
				}
			}
			cout << tento26(stoi(s.substr(C + 1, s.size() - 1))) << s.substr(1, C - 1) << endl;
		}
		else
		{
			int word;
			for(int i = 0; i < s.size(); i++)
			{
				if(s[i] > 'Z' || s[i] < 'A')
				{
					word = i - 1;
					break;
				}
			}
			cout << "R" << s.substr(word + 1, s.size() - 1) << "C" << twenty6toten(s.substr(0, word + 1)) << endl;
		}
	}
	return 0;
}

应该是10转26进制的地方出错了,现在怎么改都不行

2024/2/29 21:38
加载中...