年号字串 - 蓝桥云课 (lanqiao.cn)
我们发现每个字母都与26紧密相关,其%26的位置就是最后一个字母,由于最开始将0做为了1故在写答案时需要注意细节问题
#includeusing namespace std;char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";char a[20000];int cnt;int main(){ int n = 2019; while(n) { a[++ cnt] = s[n % 26 - 1]; n /= 26; } for(int i = cnt; i >= 1; i --)cout << a[i]; return 0;}
京公网安备 11010502049817号