Excel地址

这题想了一个小时,也只得了66分,并且是一道看起来很简单的题……

贴出代码,留给日后的自己

#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>


#define I scanf
#define OL puts
#define O printf
#define F(a,b,c) for(a=b;a<c;a++)
#define FF(a,b) for(a=0;a<b;a++)
#define FG(a,b) for(a=b-1;a>=0;a--)
#define LEN 3000
#define MAX 0x06FFFFFF
#define V vector<int>

using namespace std;



int powi(int a,int t){
    int r=1;
    while(t--){
        r*=a;
    }
    return r;
}

int main(){
//    freopen("D:/CbWorkspace/blue_bridge/Excel地址.txt","r",stdin);
    int n,i;
    I("%d",&n) ;
    int w=0;
    int cnt=1,t=n;
    while(t>0){
        cnt*=26;
        t-=cnt;
        w++;
    }
    vector<int> v;
    while(w>0){
        if(!n){        //往上借位 
            v.push_back(0);
            int p=v.size()-1;
            while(!v[p]){
                v[p]=26;
                v[p-1]--;
                p--;
            }
        }else{
            cnt=powi(26,w-1);
            if(n<=26 && w==1){
                v.push_back(n);
            }
            else v.push_back(n/cnt);
            n%=cnt;
        }
        w--;
    }
//    reverse(v.begin(),v.end());
    FF(i,v.size()){
        putchar(v[i]+'A'-1);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/TQCAI/p/8458053.html