第十届蓝桥杯B组省赛第B题

试题 B: 年号字串 (26进制数)

【问题描述】 

小明用字母 A 对应数字 1,B 对应 2,以此类推,用 Z 对应 26。对于 27 以上的数字,小明用两位或更长位的字符串来对应,例如 AA 对应 27,AB 对 应 28,AZ 对应 52,LQ 对应 329。 

#include <cstdio>

#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;

int main(){

  int m,n[10],i=0;

  scanf("%d",&m);

  while(m){

    n[i]=m-(m/26)*26+'a'-1;

    i++;

    m=m/26;

  }

  for(i=i-1;i>=0;i--)

    printf("%c",n[i]);

}

posted @ 2019-11-14 13:45  tly2022  阅读(233)  评论(0编辑  收藏  举报