主要就是先将梯子移动到最左边或者最右边
k>n/2时移动到最右边
k<=n/2时移动到最左边
然后遍历一遍
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n,k; cin >> n >> k; string poster ; cin >> poster; if(k > n/2){ for(int i = k-1 ; i < n-1; ++ i){ cout<<"RIGHT"<<endl; } for(int i = n-1; i > 0; --i){ cout<<"PRINT "<<poster[i]<<endl; cout<<"LEFT"<<endl; } cout<<"PRINT "<<poster[0]<<endl; }else{ for(int i = k-1; i>0; --i) cout<<"LEFT"<<endl; for(int i = 0; i < n-1; ++i){ cout<<"PRINT "<<poster[i]<<endl; cout<<"RIGHT"<<endl; } cout<<"PRINT "<<poster[n-1]<<endl; } }