二、年号字串(十)

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

#include<iostream>
#include<vector>
using namespace std;

vector<char> a;
int main(){
	int n;	
	cin >> n;		
	int i = 0;
	while(n){
		int x = (n - 1)%26;//取最后的字母
		a.push_back('A' + x);//放入变长数组
		n/=26;//去掉最后一个字母
	}

	for(int i = a.size() - 1;i >= 0;i--){
		cout << a[i];
	}

	return 0;

}

  

猜你喜欢

转载自www.cnblogs.com/luyuan-chen/p/11853589.html