跳到正文

题解

B4003 [GESP202406 三级] 移位 题解

Sylog约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月14日
篇幅
约 1 分钟

版本

  1. v1当前

方法思路

可以借助队列先进先出的特性来实现循环移位。先把所有大写字母按顺序存入队列,然后依据偏移量对队列进行操作。要是偏移量是 2626 的倍数,字母表不会改变;否则,就循环移动队列元素,移动次数为偏移量对 2626 取余后的结果。

解决代码

C++
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n;
    cin>>n;
    queue<char>q;
    for(int i=1;i<=26;i++){
        q.push(char(i+'A'-1));
    }
    if(n%26==0){
        while(q.size()){
            cout<<q.front();
            q.pop();
        }
    }else{
        for(int i=1;i<=n%26;i++){
            q.push(q.front());
            q.pop();
        }
        while(q.size()){
            cout<<q.front();
            q.pop();
        }
    }
    return 0;
}
原文