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 @   Marinaco  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
//雪花飘落效果
点击右上角即可分享
微信分享提示