牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A
牛客练习赛31 D 神器大师泰兹瑞与威穆
https://ac.nowcoder.com/acm/contest/218/D
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
「只要我拉动绳线,你就得随之起舞。」 ——泰兹瑞
泰兹瑞来到卡拉德许之后,由于他精湛的神器制造技术,可谓是过的如鱼得水。这次,他为自己打造了一个编辑器,称为威穆(Veim)。操作威穆时,有两种模式,具体操作如下。
在 Normal Mode 下
- 按下 i :进入 Insert Mode 。
- 按下 f :紧接着一个小写字母
char,若当前光标后(右)方有至少一个 char ,将光标移动到其所在位置,否则不移动。
- 按下 x :删除当前光标所在位的字符,后面的字符均会前移一格。
- 按下 h :将光标向左(前)移动一格,若无法移动就不移动。
- 按下 l :将光标向右(后)移动一格,若无法移动就不移动。
- 若按下了其他字符:无任何效果。
在 Insert Mode 下
- 按下非 e 小写字母 char :在光标当前位置前插入这个字母
char。
- 按下 e :退出 Insert Mode(进入 Normal Mode)。
(具体请见样例)
现在泰兹瑞的威穆中已经写入了一个字符串 s 。接下去泰兹瑞进行了一波操作(按下了若干按键),他的按键序列为
t 。现给出 s 和 t ,求这波操作之后威穆内留下的字符串。
输入描述:
两行,第一行字符串 s ,第二行字符串 t 。
输出描述:
一行,威穆里最后留下的字符串。
示例1
输入
- applese
- xfllhlia
输出
- pplaese
说明
- 初始时,字符串为 ,威穆处于 Normal Mode 。下划线表示光标所在位置。
- 第一步操作为 x ,删除当前光标所在位的字符,并且光标后移一格。字符串变为 。威穆仍处于 Normal Mode。
- 下一步操作为 f ,之后跟有一个字符 `l` 。光标后存在字符
`l` ,故移动到该位置。字符串变为 。威穆仍处于 Normal Mode。
- 下一步操作为 l ,光标后移一格。字符串变为 。威穆仍处于 Normal Mode。
- 下一步操作为 h ,光标前移一格。字符串变为 。威穆仍处于 Normal Mode。
- 下一步操作为 l ,光标后移一格。字符串变为 。威穆仍处于 Normal Mode。
- 下一步操作为 i ,威穆进入 Insert Mode。字符串仍为
。
- 下一步操作为 a ,而非 e ,故插入字符 a 。字符串变为 。
示例2
输入
pppp
iaefpfpia
输出
- appapp
备注:
1 ≤ |s|, |t| ≤ 105
s, t 均由小写拉丁字母组成。
分析
看完题目之后,意识到除了模拟别无他法,于是迅速暴力手写完成,其中normal mode中的f比较迷,,看了半天才看懂,然后提交TLE QAQ
TLE代码:
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <algorithm>
- #include <iostream>
- #include <string>
- #include <time.h>
- #include <queue>
- #include <string.h>
- #define sf scanf
- #define pf printf
- #define lf double
- #define ll long long
- #define p123 printf("123\n");
- #define pn printf("\n");
- #define pk printf(" ");
- #define p(n) printf("%d",n);
- #define pln(n) printf("%d\n",n);
- #define s(n) scanf("%d",&n);
- #define ss(n) scanf("%s",n);
- #define ps(n) printf("%s",n);
- #define sld(n) scanf("%lld",&n);
- #define pld(n) printf("%lld",n);
- #define slf(n) scanf("%lf",&n);
- #define plf(n) printf("%lf",n);
- #define sc(n) scanf("%c",&n);
- #define pc(n) printf("%c",n);
- #define gc getchar();
- #define re(n,a) memset(n,a,sizeof(n));
- #define len(a) strlen(a)
- #define LL long long
- #define eps 1e-6
- using namespace std;
- char s[],t[];
- int main() {
- ss(s);
- ss(t);
- int sta = ;//0是normal ,1是insert
- int lens = len(s);
- int lent = len(t);
- int x = ;
- for(int i = ; i < lent; i ++) {
- if(sta == ) {
- if(t[i] == 'i') {
- sta = ;
- } else if(t[i] == 'f') {
- char c = t[i+];
- for(int i = x+; i < lens; i ++) {
- if(s[i] == c) {
- x = i;
- break;
- }
- }
- i ++;
- } else if(t[i] == 'x') {
- for(int i = x; i < lens; i ++) {
- s[i] = s[i+];
- }
- lens --;
- } else if(t[i] == 'h') {
- if(x != ) {
- x --;
- }
- } else if(t[i] == 'l') {
- if(x != lens-) {
- x++;
- }
- }
- } else {
- if(t[i] == 'e') {
- sta = ;
- } else {
- for(int i = lens+; i >= x+; i --) {
- s[i] = s[i-];
- }
- s[x] = t[i];
- x ++;
- }
- }
- //ps(s) pn
- }
- ps(s) pn
- }
打过一遍之后对题目有很深的理解了,意识到用链表做比较轻松,因为中间存在一个光标,直接调整光标插入删除速度很快,
But, But! But!! But!!!
不会list啊。。。。。。。。
绝望,,,,,自闭了。。。。。
现场学list:
https://www.cnblogs.com/lalalabi/p/5060210.html
https://www.cnblogs.com/loleina/p/5179677.html
https://blog.csdn.net/zhouzhenhe2008/article/details/77428743/
https://blog.csdn.net/amoscykl/article/details/80934961
然后掌握了基本用法之后在题目里还有坑,
需要用到迭代器遍历链表,在检查的时候因为这个改了好多遍,,,还WA了一发,所以标红:如果要遍历检查一定要新建一个迭代器!!!
然后顺利AC
AC代码:
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <algorithm>
- #include <iostream>
- #include <string>
- #include <time.h>
- #include <queue>
- #include <string.h>
- #include <list>
- #define sf scanf
- #define pf printf
- #define lf double
- #define ll long long
- #define p123 printf("123\n");
- #define pn printf("\n");
- #define pk printf(" ");
- #define p(n) printf("%d",n);
- #define pln(n) printf("%d\n",n);
- #define s(n) scanf("%d",&n);
- #define ss(n) scanf("%s",n);
- #define ps(n) printf("%s",n);
- #define sld(n) scanf("%lld",&n);
- #define pld(n) printf("%lld",n);
- #define slf(n) scanf("%lf",&n);
- #define plf(n) printf("%lf",n);
- #define sc(n) scanf("%c",&n);
- #define pc(n) printf("%c",n);
- #define gc getchar();
- #define re(n,a) memset(n,a,sizeof(n));
- #define len(a) strlen(a)
- #define LL long long
- #define eps 1e-6
- using namespace std;
- list<char> l;
- char s[],t[];
- int main(){
- //ss(s);
- //ss(t);
- cin >> s >> t;
- int sta = ;//0是normal ,1是insert
- int lens = len(s);
- int lent = len(t);
- list<char>::iterator x;
- //int x = 0;
- x = l.begin();
- for(int i = ; i < lens; i ++){
- l.insert(x,s[i]);
- }
- /*for(x = l.begin();x!=l.end();++x){
- cout<<*x;
- }*/
- x = l.begin();
- for(int i = ; i < lent; i ++){
- if(sta == ){
- if(t[i] == 'i'){
- sta = ;
- }else if(t[i] == 'f'){
- char c = t[i+];
- list<char>::iterator y;
- x ++;
- y = x;
- x --;
- for(;y!=l.end();++y){
- if(*y == c){
- x = y;
- break;
- }
- }
- i ++;
- }else if(t[i] == 'x'){
- list<char>::iterator xx;
- xx = x;
- x++;
- l.erase(xx);
- //x = l.begin();
- }else if(t[i] == 'h'){
- if(x != l.begin()){
- x --;
- }
- }else if(t[i] == 'l'){
- if(x != l.end()){
- x++;
- }
- }
- }else{
- if(t[i] == 'e'){
- sta = ;
- }else{
- l.insert(x,t[i]);
- }
- }
- /*list<char>::iterator z;
- for(z = l.begin();z!=l.end();++z){
- cout<<*z;p123
- }
- cout << endl;*/
- //ps(s) pn
- }
- //ps(s) pn
- list<char>::iterator z;
- for(z = l.begin();z!=l.end();++z){
- cout<<*z;
- }
- cout << endl;
- }
牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A的更多相关文章
- 牛客练习赛31 D神器大师泰兹瑞与威穆
双链表搞完了 #include<bits/stdc++.h> using namespace std; #define maxn 1000005 int tot,bac[maxn],fa[ ...
- 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B
牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...
- 牛客练习赛31 D 最小相似度
最小相似度 链接 分析: 转化为求1的个数,这样两个串不同的位置的个数就是1的个数.那么对于一个二进制串x,它的贡献就是max{x与s[i]异或后0的个数}=>max{m-x与s[i]异或后1的 ...
- 牛客练习赛3 贝伦卡斯泰露——队列&&爆搜
题目 链接 题意:给出一个长度为 $n$ 的数列 $A_i$,问是否能将这个数列分解为两个长度为n/2的子序列,满足: 两个子序列不互相重叠(是值不能有共同元素,但位置可以交错). 两个子序列中的数要 ...
- 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)
牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...
- 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D
目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...
- 最小生成树--牛客练习赛43-C
牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...
- 牛客练习赛28-B(线段树,区间更新)
牛客练习赛28 - B 传送门 题目 qn姐姐最好了~ qn姐姐给你了一个长度为n的序列还有m次操作让你玩, 1 l r 询问区间[l,r]内的元素和 2 l r 询问区间[l,r]内的 ...
- 牛客练习赛26:D-xor序列(线性基)
链接:牛客练习赛26:D-xor序列(线性基) 题意:小a有n个数,他提出了一个很有意思的问题:他想知道对于任意的x, y,能否将x与这n个数中的任意多个数异或任意多次后变为y 题解:线性基 #inc ...
随机推荐
- FlexItem 多行测试
flex: <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...
- java之try、catch、finally
结论:try和catch相当于程序分支,finally块中不会改变变量的指针(引用地址):和final修饰的变量类似. public class Test { public static AreaRQ ...
- Android Studio计时跳转或点击跳转至主页面
这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...
- Flask-在Flask中跨请求传递数据资源
利用 Flask的底层Werkzeug是有缓存支持的,不用使用redis等第三方. 原文地址如下: https://blog.csdn.net/yannanxiu/article/details/52 ...
- tensorflow-yolo3系列配置文章汇总
yolo 网络讲解 https://blog.csdn.net/m0_37192554/article/details/81092514 https://blog.csdn.net/guleileo/ ...
- yum梳理
- ADO.NET 基本操作
概要 ADO.NET是.NET框架中的重要组件,主要用于完成C#应用程序访问数据库,类似于PHP中的PDO 使用 连接数据库 (Connection对象) 1. 连接字符串 基本语法:数据源(Data ...
- jschDemo
jsch是java的sftp实现 import com.jcraft.jsch.*; import java.io.OutputStream; public class JschStart { pub ...
- A bean with that name has already been defined in DataSourceConfiguration$Hikari.class
A bean with that name has already been defined in DataSourceConfiguration$Hikari.class 构建springcloud ...
- MYSQL性能优化(3)
优化数据库对象 1.优化表的数据类型 select * from tbl1 procedure analyse(16,256) ,会输出优化建议,结合情况优化 2.拆分表(仅Myisam) 2.1 纵 ...