标签:har class bool space 情况 ace out code alpha
题意:26进制与10进制的转换
代码实现:
#include<bits/stdc++.h>
using namespace std;
int main(void){
int t;
cin >> t;
while(t--){
string s;
cin >> s;
int len = s.size();
bool flag = 0;//flag 用来标志哪种串
for(int i = len-1; i >= 0; i--){
if(isalpha(s[i])&&isdigit(s[i-1])&&isdigit(s[i+1])){
flag = 1;
break;
}
}
if(flag){//是R---C---
int sum1 = 0;
int i;
for(i = 1; isdigit(s[i]); i++){
sum1 = sum1*10+(s[i]-'0');
}
int sum2 = 0;
for(i = i+1; i < len; i++){
sum2 = sum2*10+(s[i]-'0');
} // 取出数字
stack<char> st;
while(sum2){
int t = sum2%26;
if(t==0){ //特别注意Z这种情况
st.push('Z');
sum2--;
}
else
st.push(t-1+'A');
sum2 /= 26;
}
while(!st.empty()){
cout<<st.top();
st.pop();
}
cout<<sum1<<endl;
}else{
int sum1 = 0;
int i;
for(i = 0; isalpha(s[i]); i++){
sum1 = sum1*26 + (s[i]-'A'+1);
}
int sum2 = 0;
for(i; i < len; i++){
sum2 = sum2*10+(s[i]-'0');
}
cout<<'R'<<sum2<<'C'<<sum1<<endl;
}
}
return 0;
}
标签:har class bool space 情况 ace out code alpha
原文地址:https://www.cnblogs.com/AC-AC/p/12234212.html