求助,真心不知道哪里出了问题
查看原帖
求助,真心不知道哪里出了问题
403626
Dreamer织梦者楼主2021/4/15 11:32
#include<bits/stdc++.h>
using namespace std;
int n,len,t,ans,k,sum; 
string s;
char l[1000];
bool check(string s){
	int l;
	while(s[l]<='Z'&&s[l]>='A') l++;
	while('1'<=s[l]&&s[l]<='9') l++;
	if(l==len)  return true;
	else          return false;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	while(n--){
		cin >> s;
		len = s.size();
		if(check(s)){
			cout<<"R";
			int i=1;
			ans = s[0]-'A'+1;
			for(i=1;'A'<=s[i]&&s[i]<='Z';i++){
				ans = ans*26+s[i]-'A'+1;
			};
			t=i;
			while(s[i]>='1'&&s[i]<='9'){
				cout<<s[i];
				i++; 
			} 
			cout<<"C";
			cout<<ans<<endl;
			ans = 0;
		}else{
			int i;
			sum = s[1]-'0';
			for( i=2;s[i]!='C';i++){
				sum = sum*10+s[i]-'0'; 
			};
			i += 1;
			t=i;
			ans = s[i]-'0';
			for(int j=i+1;s[j]!='\0';j++){
				ans=ans*10+s[j]-'0';
			}
			k=0;
			while(ans){
				int x=ans%26;
				if(x==0){
					l[k]='Z';
					ans-=26;
					ans/=26;
					k++;
				}else{
					l[k] = x+64;
					ans/=26;
					k++;
				}
			}
			for(int j=k-1;j>=0;j--) cout<<l[j];
			cout<<sum<<endl;
		}
	}
	return 0;
}
2021/4/15 11:32
加载中...