2019年第十届蓝桥杯CC++ 省赛B组真题 试题 B: 年号字串

    技术2025-10-02  8

    刚开始以为对输入的数字26取余就行了,但发现会出现错误,如果输入的数字为26,按照正常的取余流程得到的结果是A,但实际的答案应该为E。这道题的答案为BYQ。

    #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char s[100]; int flag=0; if(n==0){ cout<<"0"<<endl; } while(n!=0){ s[flag] = str[(n%26)-1]; if((n%26)==0){ s[flag]='Z'; } n/=26; flag++; if(n==1){ break; } } for(int i=flag-1;i>=0;i--){ cout<<s[i]; } return 0; }

     

    Processed: 0.013, SQL: 12