日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hihoCoder1228(2015北京网络赛B题)

發布時間:2025/3/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hihoCoder1228(2015北京网络赛B题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

給出一個文本編輯器的容量,給出老板輸入的字符串,小寫字母代表文本,大寫字母代表命令:

L:光標左移;

R:光標右移;

S:在insert模式和另一個輸入模式中切換;

D:刪除光標后面的一個字符;

B:刪除光標前面的一個字符;

C:復制;

V:粘貼;


思路:

模擬。結果這題我們WA了全場。賽后回去檢查,發現了我愚蠢的地方。。。就是D操作時,如果在復制狀態下,我把刪除的起點選錯了。。。教訓啊!!!


代碼:

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cstdlib> #include<cmath> #include<map> #include<vector> #include<stack> #include<queue> #include<string> #include<climits>using namespace std;string ans,cc,in;int main() {int t;cin>>t;while(t--){int lim;cin>>lim>>in;int len=in.length();int insertmode=1;int copy=-1;int pos=0;ans="";cc="";int real1=-1,real2=-1;for(int i=0;i<len;i++){if(in[i]>='a'&&in[i]<='z'){if(insertmode==1){if(ans.length()>=lim)continue;ans.insert(pos,1,in[i]);pos++;}else {if(pos==ans.length()) {if(ans.length() == lim) continue ;ans+=in[i];pos++;}else {ans[pos] = in[i];pos++;}}copy=-1;}else{int tmplen=ans.length();if(in[i]=='L'){if(pos>0)pos--;}else if(in[i]=='R'){// cout<<"tt="<<tmplen<<endl;if(pos<(tmplen))pos++;}else if(in[i]=='S'){if(insertmode==1)insertmode=0;else insertmode=1;copy=-1;}else if(in[i]=='D'){if(copy==1){int tt=real1;real1=min(tt,pos);real2=max(tt,pos);//cout<<real1<<" "<<real2<<endl;ans.erase(real1,real2-real1);//ans.erase(pos,real2-real1);這里寫錯了}else if(pos<tmplen)ans.erase(pos,1);copy=-1;}else if(in[i]=='B'){// cout<<"==="<<ans<<endl;//cout<<"pos="<<pos<<endl;if(pos>0){ans.erase(pos-1,1);pos--;}copy=-1;// cout<<"---"<<ans<<endl;}else if(in[i]=='C'){if(copy==-1){real1=real2=pos;copy=1;}else{ cc="";int tt=real1;real1=min(tt,pos);real2=max(tt,pos);// cout<<real1<<" "<<real2<<endl;// cout<<pos1<<" "<<pos1<<endl;// puts("----");cc=ans.substr(real1,real2-real1);// puts("----");// cout<<"cc="<<cc<<endl;copy=-1;}}else if(in[i]=='V'){if(insertmode==1){//cout<<cc<<" "<<pos<<" "<<ans<<endl;if(cc.length()==0)continue;if(cc.length()+ans.length()>lim)continue;ans.insert(pos,cc);pos+=cc.length(); }else {//cout<<cc<<" "<<pos<<" "<<ans<<endl;if(pos+cc.length()>lim)continue;ans.replace(pos,cc.length(),cc);pos+=cc.length();}copy=-1;}}//cout<<cc<<endl;// cout<<"----"<<ans<<" "<<pos<<" "<<pos1<<" "<<pos2<<endl;}if(ans.length()==0)cout<<"NOTHING"<<endl;else cout<<ans<<endl;}return 0; }

總結

以上是生活随笔為你收集整理的hihoCoder1228(2015北京网络赛B题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。