zoukankan      html  css  js  c++  java
  • 牛客在线编程_万万没想到之聪明的编辑

    题目地址
    给定字符串,连续三个相同的删除其中一个,连续两对的就删除第二对的其中一个,输出删除后的字符串。

    • 字符串带有删除的模拟我习惯用链表来做,如果直接用数组打删除标记应该也是能做。

    code

    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e5+50;
    int T;
    char s[N];
    struct node{
        char c;
        int next;
    }ls[N];
    int main(){
        scanf("%d",&T);
        while(T--){
            scanf("%s",s+1);
            int n=strlen(s+1);
            for(int i=1;i<=n;i++){
                ls[i]=node{s[i],i+1};
            }
            ls[n].next=-1;
            int now=1;
            while(now!=-1){
                if(ls[now].next!=-1
                   && ls[ls[now].next].next!=-1
                   && ls[now].c==ls[ls[now].next].c
                   && ls[now].c==ls[ls[ls[now].next].next].c){
                    ls[now].next=ls[ls[now].next].next;
                }else if(ls[now].next!=-1
                         && ls[ls[ls[now].next].next].next!=-1
                         && ls[ls[now].next].next!=-1
                         && ls[now].c==ls[ls[now].next].c
                         && ls[ls[ls[now].next].next].c==ls[ls[ls[ls[now].next].next].next].c
                         && ls[now].c!=ls[ls[ls[now].next].next].c){
                    ls[ls[now].next].next=ls[ls[ls[now].next].next].next;
                }else{
                    now=ls[now].next;
                }
            }
            now=1;
            while(now!=-1){
                printf("%c",ls[now].c);
                now=ls[now].next;
            }
            printf("
    ");
            memset(ls,0,sizeof(node)*(n+5));
        }
        return 0;
    }
    
  • 相关阅读:
    G
    ZOJ 3782
    23.内存池
    22.boost图模板
    21.boost Ford最短路径算法(效率低)
    20.boost dijkstra最短路径算法
    19.boost A*算法
    18.boost 图的拓扑排序
    17.广度优先遍历bfs
    16.boost图深度优先遍历DFS
  • 原文地址:https://www.cnblogs.com/zxcoder/p/12227126.html
Copyright © 2011-2022 走看看