5.Excel地址

题目链接:https://www.lanqiao.cn/problems/96/learning/?page=1&first_category_id=1&second_category_id=3

题意:

输出n所代表的excel列数,126:AZ 27:AA 28:AB 53:BA

思路:

感觉有点抽象,将n转换为26进制数:n不断%26,/26,直到n=0,将记录的数倒着看
需要注意26进制数共有:0~25 26个数,但是题目里没有0,所以每次循环都要让n--

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define endl "\n"
#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll llmax=LLONG_MAX;
const int maxn=1e5+5;
const int mod=1e9+7;
int n;
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0);
	cin>>n;
	vector<int>ans;
	while(n){
		n--;
		ans.pb(n%26);
		n/=26;
	}
	for(int i=ans.size()-1;i>=0;i--){
		cout<<(char)('A'+ans[i]);
	}
	return 0;
}


posted @ 2025-02-20 11:59  Marinaco  阅读(15)  评论(0)    收藏  举报
//雪花飘落效果