清北学堂模拟赛d6t1 角谷猜想

分析:不用删数字,我们考虑加入数字,维护一个栈,把不是4和7的数加进去,遇到3看栈顶是不是1,是的话弹出来就可以了.

#include <bits/stdc++.h>
#define N 100005
using namespace std;
int n,top;
char c[N],st[N];
int main()
{
    freopen("kakutani.in","r",stdin);
    freopen("kakutani.out","w",stdout);
    cin>>n;
    while(n--)
    {
        scanf("%s",c+1);
        int l=strlen(c+1);
        for(int i=1;i<=l;i++)
        {
            if(c[i]!='4'&&c[i]!='7')
                if(c[i]=='3'&&st[top]=='1')top--;
                    else st[++top]=c[i];
        }
        if(!top)cout<<0;for(int i=1;i<=top;i++)cout<<st[i];cout<<endl;
        top=0;
    }

    return 0;
}

 

posted @ 2017-10-06 18:34  zbtrs  阅读(237)  评论(0编辑  收藏  举报