您的位置:首页 > 其它

[河南省ACM省赛-第四届] 序号互换 (nyoj 303)

2015-04-01 21:03 295 查看
相似与27进制的转换

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<stack>
using namespace std;

int main(){
int t;
string s;
cin>>t;
while(t--)
{
cin>>s;
if(s[0] >= 'A') {
int res = 0;
int len = s.length();
for(int i=0; i<len; i++){
res = res*26+s[i]-'A'+1;
}
cout<<res<<endl;
} else {
string res;
int n = atoi(s.c_str());
while(n){
if(n%26 == 0){
res += 'Z';
n -= 26;
}
else
res += n%26+'A'-1;
n /= 26;
}
reverse(res.begin(), res.end());
cout<<res<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: