相似与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;
}
 posted on 2015-04-01 21:03  平和之心  阅读(115)  评论(0编辑  收藏  举报