牛客练习赛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

输入

  1. applese
  2. xfllhlia

输出

  1. 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

输出

  1. appapp

备注:

1 ≤ |s|, |t| ≤ 105
s, t 均由小写拉丁字母组成。

分析

  看完题目之后,意识到除了模拟别无他法,于是迅速暴力手写完成,其中normal mode中的f比较迷,,看了半天才看懂,然后提交TLE QAQ

TLE代码:

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <string>
  7. #include <time.h>
  8. #include <queue>
  9. #include <string.h>
  10. #define sf scanf
  11. #define pf printf
  12. #define lf double
  13. #define ll long long
  14. #define p123 printf("123\n");
  15. #define pn printf("\n");
  16. #define pk printf(" ");
  17. #define p(n) printf("%d",n);
  18. #define pln(n) printf("%d\n",n);
  19. #define s(n) scanf("%d",&n);
  20. #define ss(n) scanf("%s",n);
  21. #define ps(n) printf("%s",n);
  22. #define sld(n) scanf("%lld",&n);
  23. #define pld(n) printf("%lld",n);
  24. #define slf(n) scanf("%lf",&n);
  25. #define plf(n) printf("%lf",n);
  26. #define sc(n) scanf("%c",&n);
  27. #define pc(n) printf("%c",n);
  28. #define gc getchar();
  29. #define re(n,a) memset(n,a,sizeof(n));
  30. #define len(a) strlen(a)
  31. #define LL long long
  32. #define eps 1e-6
  33. using namespace std;
  34. char s[],t[];
  35. int main() {
  36. ss(s);
  37. ss(t);
  38. int sta = ;//0是normal ,1是insert
  39. int lens = len(s);
  40. int lent = len(t);
  41. int x = ;
  42. for(int i = ; i < lent; i ++) {
  43. if(sta == ) {
  44. if(t[i] == 'i') {
  45. sta = ;
  46. } else if(t[i] == 'f') {
  47. char c = t[i+];
  48. for(int i = x+; i < lens; i ++) {
  49. if(s[i] == c) {
  50. x = i;
  51. break;
  52. }
  53. }
  54.  
  55. i ++;
  56. } else if(t[i] == 'x') {
  57. for(int i = x; i < lens; i ++) {
  58. s[i] = s[i+];
  59. }
  60. lens --;
  61. } else if(t[i] == 'h') {
  62. if(x != ) {
  63. x --;
  64. }
  65. } else if(t[i] == 'l') {
  66. if(x != lens-) {
  67. x++;
  68. }
  69. }
  70. } else {
  71. if(t[i] == 'e') {
  72. sta = ;
  73. } else {
  74. for(int i = lens+; i >= x+; i --) {
  75. s[i] = s[i-];
  76. }
  77. s[x] = t[i];
  78. x ++;
  79. }
  80. }
  81. //ps(s) pn
  82. }
  83. ps(s) pn
  84. }

 

打过一遍之后对题目有很深的理解了,意识到用链表做比较轻松,因为中间存在一个光标,直接调整光标插入删除速度很快,

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代码:

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <string>
  7. #include <time.h>
  8. #include <queue>
  9. #include <string.h>
  10. #include <list>
  11. #define sf scanf
  12. #define pf printf
  13. #define lf double
  14. #define ll long long
  15. #define p123 printf("123\n");
  16. #define pn printf("\n");
  17. #define pk printf(" ");
  18. #define p(n) printf("%d",n);
  19. #define pln(n) printf("%d\n",n);
  20. #define s(n) scanf("%d",&n);
  21. #define ss(n) scanf("%s",n);
  22. #define ps(n) printf("%s",n);
  23. #define sld(n) scanf("%lld",&n);
  24. #define pld(n) printf("%lld",n);
  25. #define slf(n) scanf("%lf",&n);
  26. #define plf(n) printf("%lf",n);
  27. #define sc(n) scanf("%c",&n);
  28. #define pc(n) printf("%c",n);
  29. #define gc getchar();
  30. #define re(n,a) memset(n,a,sizeof(n));
  31. #define len(a) strlen(a)
  32. #define LL long long
  33. #define eps 1e-6
  34. using namespace std;
  35. list<char> l;
  36. char s[],t[];
  37. int main(){
  38. //ss(s);
  39. //ss(t);
  40. cin >> s >> t;
  41. int sta = ;//0是normal ,1是insert
  42. int lens = len(s);
  43. int lent = len(t);
  44. list<char>::iterator x;
  45. //int x = 0;
  46. x = l.begin();
  47. for(int i = ; i < lens; i ++){
  48. l.insert(x,s[i]);
  49. }
  50.  
  51. /*for(x = l.begin();x!=l.end();++x){
  52. cout<<*x;
  53. }*/
  54. x = l.begin();
  55. for(int i = ; i < lent; i ++){
  56. if(sta == ){
  57. if(t[i] == 'i'){
  58. sta = ;
  59. }else if(t[i] == 'f'){
  60. char c = t[i+];
  61. list<char>::iterator y;
  62. x ++;
  63. y = x;
  64. x --;
  65. for(;y!=l.end();++y){
  66. if(*y == c){
  67. x = y;
  68. break;
  69. }
  70. }
  71. i ++;
  72. }else if(t[i] == 'x'){
  73.  
  74. list<char>::iterator xx;
  75. xx = x;
  76. x++;
  77. l.erase(xx);
  78.  
  79. //x = l.begin();
  80. }else if(t[i] == 'h'){
  81. if(x != l.begin()){
  82. x --;
  83. }
  84. }else if(t[i] == 'l'){
  85. if(x != l.end()){
  86. x++;
  87. }
  88. }
  89. }else{
  90. if(t[i] == 'e'){
  91. sta = ;
  92. }else{
  93. l.insert(x,t[i]);
  94. }
  95. }
  96. /*list<char>::iterator z;
  97. for(z = l.begin();z!=l.end();++z){
  98. cout<<*z;p123
  99. }
  100. cout << endl;*/
  101. //ps(s) pn
  102. }
  103. //ps(s) pn
  104. list<char>::iterator z;
  105. for(z = l.begin();z!=l.end();++z){
  106. cout<<*z;
  107. }
  108. cout << endl;
  109. }

牛客练习赛31 D 神器大师泰兹瑞与威穆 STL,模拟 A的更多相关文章

  1. 牛客练习赛31 D神器大师泰兹瑞与威穆

    双链表搞完了 #include<bits/stdc++.h> using namespace std; #define maxn 1000005 int tot,bac[maxn],fa[ ...

  2. 牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 逻辑,博弈 B

    牛客练习赛31 B 赞迪卡之声妮莎与奥札奇 https://ac.nowcoder.com/acm/contest/218/B 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 2621 ...

  3. 牛客练习赛31 D 最小相似度

    最小相似度 链接 分析: 转化为求1的个数,这样两个串不同的位置的个数就是1的个数.那么对于一个二进制串x,它的贡献就是max{x与s[i]异或后0的个数}=>max{m-x与s[i]异或后1的 ...

  4. 牛客练习赛3 贝伦卡斯泰露——队列&&爆搜

    题目 链接 题意:给出一个长度为 $n$ 的数列 $A_i$,问是否能将这个数列分解为两个长度为n/2的子序列,满足: 两个子序列不互相重叠(是值不能有共同元素,但位置可以交错). 两个子序列中的数要 ...

  5. 牛客练习赛48 A· 小w的a+b问题 (贪心,构造,二进制)

    牛客练习赛48 A· 小w的a+b问题 链接:https://ac.nowcoder.com/acm/contest/923/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C ...

  6. 【并查集缩点+tarjan无向图求桥】Where are you @牛客练习赛32 D

    目录 [并查集缩点+tarjan无向图求桥]Where are you @牛客练习赛32 D PROBLEM SOLUTION CODE [并查集缩点+tarjan无向图求桥]Where are yo ...

  7. 最小生成树--牛客练习赛43-C

    牛客练习赛43-C 链接: https://ac.nowcoder.com/acm/contest/548/C 来源:牛客网 题目描述 ​ 立华奏是一个刚刚开始学习 OI 的萌新. 最近,实力强大的 ...

  8. 牛客练习赛28-B(线段树,区间更新)

    牛客练习赛28 - B 传送门 题目 qn姐姐最好了~ ​ qn姐姐给你了一个长度为n的序列还有m次操作让你玩, ​ 1 l r 询问区间[l,r]内的元素和 ​ 2 l r 询问区间[l,r]内的 ...

  9. 牛客练习赛26:D-xor序列(线性基)

    链接:牛客练习赛26:D-xor序列(线性基) 题意:小a有n个数,他提出了一个很有意思的问题:他想知道对于任意的x, y,能否将x与这n个数中的任意多个数异或任意多次后变为y 题解:线性基 #inc ...

随机推荐

  1. FlexItem 多行测试

    flex: <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...

  2. java之try、catch、finally

    结论:try和catch相当于程序分支,finally块中不会改变变量的指针(引用地址):和final修饰的变量类似. public class Test { public static AreaRQ ...

  3. Android Studio计时跳转或点击跳转至主页面

    这个总体来说是比较简单的,计时跳转一般调用Android Studio中的Handler方法. 一.发生点击事件跳转页面 mBtnTextView = (Button) findViewById(R. ...

  4. Flask-在Flask中跨请求传递数据资源

    利用 Flask的底层Werkzeug是有缓存支持的,不用使用redis等第三方. 原文地址如下: https://blog.csdn.net/yannanxiu/article/details/52 ...

  5. tensorflow-yolo3系列配置文章汇总

    yolo 网络讲解 https://blog.csdn.net/m0_37192554/article/details/81092514 https://blog.csdn.net/guleileo/ ...

  6. yum梳理

  7. ADO.NET 基本操作

    概要 ADO.NET是.NET框架中的重要组件,主要用于完成C#应用程序访问数据库,类似于PHP中的PDO 使用 连接数据库 (Connection对象) 1. 连接字符串 基本语法:数据源(Data ...

  8. jschDemo

    jsch是java的sftp实现 import com.jcraft.jsch.*; import java.io.OutputStream; public class JschStart { pub ...

  9. 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 ...

  10. MYSQL性能优化(3)

    优化数据库对象 1.优化表的数据类型 select * from tbl1 procedure analyse(16,256) ,会输出优化建议,结合情况优化 2.拆分表(仅Myisam) 2.1 纵 ...