hihocoder 1228 Mission Impossible 6
2015-09-23 22:24
447 查看
题意:定义一些文本编辑器的常规操作
L:光标左移
R:光标右移
S:按下insert
D:按下delete
B:按下backspace,跟三次元不同的是shift操作对它无影响
C:第一次按下相当于shift,第二次按下相当于ctrl+c。跟三次元不同的是ctrl+c时,若光标没有选择字符,则相当于对剪切板进行清空。在三次元里则是对剪切板无影响。
V:相当于ctrl+v
其它字符:输入这个字符
文本编辑器最大可容纳字符长度为M,若输入操作跟V操作使得新串大于M,则此操作无效。
最后输出结果。
做法:理解清楚题意后一般不会错,直接模拟。我用的是容器string一顿乱搞。
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int n,now;
bool mode;
string ss;
vector<int>dx;
void L()
{
if(now>0)
now--;
}
void R()
{
if(now<ss.length())
now++;
}
void S()
{
mode=!mode;
dx.clear();
}
string cb;
void D()
{
if(dx.size())
{
dx.push_back(now);
sort(dx.begin(),dx.end());
ss.erase(ss.begin()+dx[0],ss.begin()+dx[1]);
now=dx[0];
dx.clear();
}
else if(now<ss.length())
ss.erase(ss.begin()+now,ss.begin()+now+1);
}
void B()
{
if(now>0)
{
ss.erase(ss.begin()+now-1,ss.begin()+now);
now--;
}
dx.clear();
}
void C()
{
dx.push_back(now);
if(dx.size()==2)
{
sort(dx.begin(),dx.end());
cb=ss.substr(dx[0],dx[1]-dx[0]);
dx.clear();
}
}
void V()
{
if(cb.length())
{
if(!mode)
{
if(ss.length()+cb.length()<=n)
{
int len=cb.length();
for(int i=0;i<len;i++,now++)
ss.insert(ss.begin()+now,cb[i]);
}
}
else
{
if(now+cb.length()+1<=n)
{
int len1=cb.length(),len2=ss.length();
for(int i=0;i<len1;i++,now++)
{
if(now>=len2)
ss.insert(ss.begin()+now,cb[i]);
else
ss[now]=cb[i];
}
}
}
}
dx.clear();
}
int main()
{
int T;
cin>>T;
while(T--)
{
string s;
cin>>n>>s;
int len=s.length();
mode=0;
dx.clear();
ss.clear();
cb.clear();
now=0;
for(int i=0;n!=0&&i<len;i++)
{
if(s[i]=='L')
L();
else if(s[i]=='R')
R();
else if(s[i]=='S')
S();
else if(s[i]=='D')
D();
else if(s[i]=='B')
B();
else if(s[i]=='C')
C();
else if(s[i]=='V')
V();
else
{
if(mode&&now<ss.length())
ss[now++]=s[i];
else if(ss.length()<n)
{
ss.insert(ss.begin()+now,s[i]);
now++;
}
dx.clear();
}
}
if(ss.size())
cout<<ss<<endl;
else
cout<<"NOTHING"<<endl;
}
}
时间限制:1000ms
单点时限:1000ms
内存限制:256MB
You must have seen the very famous movie series,"Mission Impossible", from 1 to 4. And "Mission Impossible 5" is now on screen in China. Tom Cruise is just learning programming through my MOOC course, and he wants
a good score. So I made him divulge the story of "Mission Impossible 6".
In "Mission Impossible 6", Ethan Hunt risks his life to install a mini camera in Bad Boss's room, in order to peep at the work Bad Boss does on his computer. Unfortunately, Bad Boss moves his desk to get more sunshine,
and after that Ethan can't see the computer screen through the camera. Fortunately, Ethan can still see the keyboard. So, Ethan wants to know what Bad Boss writes on his computer by watching Bad Boss's keyboard inputs. That job is neither exciting nor risky,
so it's really impossible for Ethan to accomplish --- that's why Tom Cruise wants to learn programming.
To simplified the problem, we assume that Bad Boss is editing a one line document, and the document consists of only lowercase letters. At first, there are nothing in the text editor window except a caret blinking
at the left-most position (the starting position of the line). When Bad Boss input a lowercase letter, the letter appears at the right side of the caret, and then the caret moves to the right side of the letter just inputted. The text editor can switch between
"insert mode" and "overwrite mode". When it's in "overwrite mode", the newly inputted letter will overwrite the letter which is on the right of the caret(if there is one). If it's in "insert mode", the newly inputted letter will be inserted before the letter
which is originally on the right of the caret.
Besides inputting lowercase letters, Bad Boss can do some operations by inputting some uppercase letters, as described below:
'L' : Moves the caret toward left by one letter. If the caret is already at the start of the line, then nothing happens.
'R': Moves the caret toward right by one letter. If the caret is already at the end of the line(it means that there are no letters on the right side of the caret), then nothing happens.
'S': Switch between "overwrite mode" and "insert mode". At the beginning, it's in "insert mode".
'D': Delete a letter which is on the right of the caret. If the caret is already at the end of the line, then nothing happens. 'D' also has other effect which is described in 'C' operation below.
'B': Delete a letter which is on the left of the caret. If the caret is already at the start of the line, then nothing happens.
'C': Copy something to the clipboard. At first , there is nothing in the clipboard, and the "copy status" of the editor is set to "NOTHING". When key 'C' is pressed:
If copy status is "NOTHING", copy status will be changed into "START", and the current position of caret is saved as "copy position 1".
if copy status is "START ", copy status will be changed into "NOTHING" and the letters between current caret position and the saved "copy position 1" will be copied into clipboard(The old content in the clipboard
is replaced). If those two positions are the same, clipboard will be cleared.
Please note that , if any letter except 'L' , 'R' and 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, not affecting the inputted letter taking its own effect as
mention above. If 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, and the letters between current caret position and "copy position 1" will be deleted.
'V': Paste the content in the clipboard into the right of the caret. If there is nothing in the clipboard, nothing happens. In "insertion mode", the pasted content is inserted. If it's in "overwrite mode" and there
are k letters in the clipboard, then k letters will be overwrote. In "overwrite mode", if the number of letters on the right side of the caret is less then k, those letters will also all be replaced by the letters in the clipboard. After the paste operation,
the caret moves to the right of the last pasted letter.
The content of the text line will never exceed M letters. Any input which will cause the content exceed M letters must be ignored. Especially, when you paste, you either paste all content in the clipboard, or paste
nothing due to the text length limit.
The first line of the input is a integer T(T <= 20), meaning that there are T test cases. The T lines follow, and each line is a test case.
For each test case:
A integer M (0 <= M <= 10,000) goes first ,meaning the text length limitation. Then some letters follow, describing what Bad Boss inputs. The total number of letters in one test case is no more than 10,000.
For each test case, print the result which Bad Boss gets. If the result is nothing, print "NOTHING".
样例输入
样例输出
L:光标左移
R:光标右移
S:按下insert
D:按下delete
B:按下backspace,跟三次元不同的是shift操作对它无影响
C:第一次按下相当于shift,第二次按下相当于ctrl+c。跟三次元不同的是ctrl+c时,若光标没有选择字符,则相当于对剪切板进行清空。在三次元里则是对剪切板无影响。
V:相当于ctrl+v
其它字符:输入这个字符
文本编辑器最大可容纳字符长度为M,若输入操作跟V操作使得新串大于M,则此操作无效。
最后输出结果。
做法:理解清楚题意后一般不会错,直接模拟。我用的是容器string一顿乱搞。
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
int n,now;
bool mode;
string ss;
vector<int>dx;
void L()
{
if(now>0)
now--;
}
void R()
{
if(now<ss.length())
now++;
}
void S()
{
mode=!mode;
dx.clear();
}
string cb;
void D()
{
if(dx.size())
{
dx.push_back(now);
sort(dx.begin(),dx.end());
ss.erase(ss.begin()+dx[0],ss.begin()+dx[1]);
now=dx[0];
dx.clear();
}
else if(now<ss.length())
ss.erase(ss.begin()+now,ss.begin()+now+1);
}
void B()
{
if(now>0)
{
ss.erase(ss.begin()+now-1,ss.begin()+now);
now--;
}
dx.clear();
}
void C()
{
dx.push_back(now);
if(dx.size()==2)
{
sort(dx.begin(),dx.end());
cb=ss.substr(dx[0],dx[1]-dx[0]);
dx.clear();
}
}
void V()
{
if(cb.length())
{
if(!mode)
{
if(ss.length()+cb.length()<=n)
{
int len=cb.length();
for(int i=0;i<len;i++,now++)
ss.insert(ss.begin()+now,cb[i]);
}
}
else
{
if(now+cb.length()+1<=n)
{
int len1=cb.length(),len2=ss.length();
for(int i=0;i<len1;i++,now++)
{
if(now>=len2)
ss.insert(ss.begin()+now,cb[i]);
else
ss[now]=cb[i];
}
}
}
}
dx.clear();
}
int main()
{
int T;
cin>>T;
while(T--)
{
string s;
cin>>n>>s;
int len=s.length();
mode=0;
dx.clear();
ss.clear();
cb.clear();
now=0;
for(int i=0;n!=0&&i<len;i++)
{
if(s[i]=='L')
L();
else if(s[i]=='R')
R();
else if(s[i]=='S')
S();
else if(s[i]=='D')
D();
else if(s[i]=='B')
B();
else if(s[i]=='C')
C();
else if(s[i]=='V')
V();
else
{
if(mode&&now<ss.length())
ss[now++]=s[i];
else if(ss.length()<n)
{
ss.insert(ss.begin()+now,s[i]);
now++;
}
dx.clear();
}
}
if(ss.size())
cout<<ss<<endl;
else
cout<<"NOTHING"<<endl;
}
}
时间限制:1000ms
单点时限:1000ms
内存限制:256MB
描述
You must have seen the very famous movie series,"Mission Impossible", from 1 to 4. And "Mission Impossible 5" is now on screen in China. Tom Cruise is just learning programming through my MOOC course, and he wantsa good score. So I made him divulge the story of "Mission Impossible 6".
In "Mission Impossible 6", Ethan Hunt risks his life to install a mini camera in Bad Boss's room, in order to peep at the work Bad Boss does on his computer. Unfortunately, Bad Boss moves his desk to get more sunshine,
and after that Ethan can't see the computer screen through the camera. Fortunately, Ethan can still see the keyboard. So, Ethan wants to know what Bad Boss writes on his computer by watching Bad Boss's keyboard inputs. That job is neither exciting nor risky,
so it's really impossible for Ethan to accomplish --- that's why Tom Cruise wants to learn programming.
To simplified the problem, we assume that Bad Boss is editing a one line document, and the document consists of only lowercase letters. At first, there are nothing in the text editor window except a caret blinking
at the left-most position (the starting position of the line). When Bad Boss input a lowercase letter, the letter appears at the right side of the caret, and then the caret moves to the right side of the letter just inputted. The text editor can switch between
"insert mode" and "overwrite mode". When it's in "overwrite mode", the newly inputted letter will overwrite the letter which is on the right of the caret(if there is one). If it's in "insert mode", the newly inputted letter will be inserted before the letter
which is originally on the right of the caret.
Besides inputting lowercase letters, Bad Boss can do some operations by inputting some uppercase letters, as described below:
'L' : Moves the caret toward left by one letter. If the caret is already at the start of the line, then nothing happens.
'R': Moves the caret toward right by one letter. If the caret is already at the end of the line(it means that there are no letters on the right side of the caret), then nothing happens.
'S': Switch between "overwrite mode" and "insert mode". At the beginning, it's in "insert mode".
'D': Delete a letter which is on the right of the caret. If the caret is already at the end of the line, then nothing happens. 'D' also has other effect which is described in 'C' operation below.
'B': Delete a letter which is on the left of the caret. If the caret is already at the start of the line, then nothing happens.
'C': Copy something to the clipboard. At first , there is nothing in the clipboard, and the "copy status" of the editor is set to "NOTHING". When key 'C' is pressed:
If copy status is "NOTHING", copy status will be changed into "START", and the current position of caret is saved as "copy position 1".
if copy status is "START ", copy status will be changed into "NOTHING" and the letters between current caret position and the saved "copy position 1" will be copied into clipboard(The old content in the clipboard
is replaced). If those two positions are the same, clipboard will be cleared.
Please note that , if any letter except 'L' , 'R' and 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, not affecting the inputted letter taking its own effect as
mention above. If 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, and the letters between current caret position and "copy position 1" will be deleted.
'V': Paste the content in the clipboard into the right of the caret. If there is nothing in the clipboard, nothing happens. In "insertion mode", the pasted content is inserted. If it's in "overwrite mode" and there
are k letters in the clipboard, then k letters will be overwrote. In "overwrite mode", if the number of letters on the right side of the caret is less then k, those letters will also all be replaced by the letters in the clipboard. After the paste operation,
the caret moves to the right of the last pasted letter.
The content of the text line will never exceed M letters. Any input which will cause the content exceed M letters must be ignored. Especially, when you paste, you either paste all content in the clipboard, or paste
nothing due to the text length limit.
输入
The first line of the input is a integer T(T <= 20), meaning that there are T test cases. The T lines follow, and each line is a test case.For each test case:
A integer M (0 <= M <= 10,000) goes first ,meaning the text length limitation. Then some letters follow, describing what Bad Boss inputs. The total number of letters in one test case is no more than 10,000.
输出
For each test case, print the result which Bad Boss gets. If the result is nothing, print "NOTHING".样例输入
8 100 abcdeLCLLD 5 abcLkjff 15 abcBBdeLLDDxzDDDDRRRR 25 abcdefgLLLSxyzSLLku 20 abcdefgLLCkLLCRRRRRCLV 20 abcdefgLLCkLLCRRRRCLLLSV 30 abcdeCLLCRRVCLRCabVkz 10 abcBBBLB
样例输出
abe abkjc axz abcdxkuyz abcdekfekfgg abcdeekfg abcdedeabkz NOTHING
相关文章推荐
- uva 1327 - King's Quest(强联通)
- UVA110模拟出Pascal的8个数字的排序代码插入式递归
- HDU 5437 Alisha’s Party(优先队列)(2015网络赛长春站)
- HDU 5458(Stability-LCT维护连通图2点间割边个数)
- 创建线程的第三种方法-callable futureTask
- process mining(data source+d)+算法第二讲
- 欢迎使用CSDN-markdown编辑器
- Java并发知识点总结(上)
- [cyber security][php]pfSense目录遍历漏洞分析
- 将链表中的所有元素为奇数的节点移到元素为偶数节点的前面,并保证奇数之间顺序不变,偶数之间顺序不变。
- 数据挖掘十大算法
- MySQL 新增用户 权限分配 远程登录
- 全面讲解Tomcat下SSL证书的配置(五)
- 【UIKit-124-8】#import <UIKit/UIView.h>
- ocp-v13-347
- 找出n个字符串中出现次数最多的字符串。
- 浅谈Java中的hashcode方法
- OWIN初探
- xtrabackup实现mysql数据库的完全备份和增量备份
- ubuntu下source、sh、bash、./执行脚本的区别