一个奇怪的问题,程序最后什么都无法输出
查看原帖
一个奇怪的问题,程序最后什么都无法输出
100461
赤城舰长_cpp楼主2022/4/21 20:15
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<vector>

#define ll long long

using namespace std;

const int N=200,M=20010;

int n;
string s;
string pre[N];
int seg[M];
int ch[M][100];
bool flag[M];
int tot;
int i;
int len;
bool f[N];
int cnt;

inline int read()
{
    int num=0,sign=1;
    char x;
    while( (x=getchar())<'0' || x>'9' )
        if(x=='-') sign=-1;
    num=x-'0';
    while( (x=getchar())>='0' && x<='9' )
        num=num*10+x-'0';
    return num*sign;
}

bool pan(char x)
{
	if(x>='A' && x<='Z') return true;
    else if(x>='a' && x<='z')return true;
    else if(x=='_') return true;
    else if(x>='0' && x<=9) return true;
    else return false;
}

int tent(char x)
{
    if(x>='A' && x<='Z')
        return x-'A'+1;
    if(x>='a' && x<='z')
        return x-'a'+26+1;
    
    if(x>='0' && x<='9') return 26+26+x-'0'+1;
    if(x=='_') return 26+26+10+1;
    return 26+26+10+2;
}

void insert()
{
    int t=0;
    for(;s[i]!=' ';i++)
    {
        int tt=tent(s[i]);
        if(!ch[t][tt])
            ch[t][tt]=++tot;
        t=ch[t][tt];
    }
    flag[t]=true;
    i++;
    seg[t]=++cnt;
    for(;i<len;i++)
        pre[seg[t]]+=s[i];
}

int check1(int,int,int);

void work(int);

void check();

void delet()
{
    int t=0;
    for(;i<len;i++)
    {
        int tt=tent(s[i]);
        t=ch[t][tt];
    }
    flag[t]=false;
}



int main()
{
    freopen("preprocessor.in","r",stdin);
    freopen("preprocessor.out","w",stdout);
    n=read();
    while(n--)
    {
        getline(cin,s);
        len=s.size();
        if(s[0]=='#' && s[1]=='d')
        {
            for(i=0;s[i]!=' ';i++) ;i++;
            insert();
        }
        else if(s[0]=='#' && s[1]=='u')
        {
            for(i=0;s[i]!=' ';i++) ;i++;
            delet();
        }
        else
        {
            for(i=0;i<len;i++)
            {
                if(pan(s[i]))check();
                else cout<<s[i];
            }
        }
        printf("\n");
    }
    return 0;
}

void work(int x)
{
    int len1=pre[x].size();
    for(int j=0;j<len1;j++)
    {
        if(pan(pre[x][j])) 
		{
			j=check1(x,j,len1);cout<<pre[x][j];
		}
        else cout<<pre[x][j];
    }
}

int check1(int x,int j,int len1)
{
    bool ff=true;
    int t=0;string ans="\0";
    for(;j<len1;j++)
    {
        if(!pan(pre[x][j])) break;
        int tt=tent(pre[x][j]);
        if(!ch[t][tt])
        {
            ff=false;
            break;
        }
        ans+=pre[x][j];
        t=ch[t][tt];
    }
    if(ff && flag[t] && !f[seg[t]])
    {
        f[seg[t]]=true;
        work(seg[t]);
        f[seg[t]]=false;
    }
    else
    {
        cout<<ans;
    }
    return j;
}

void check()
{
    bool ff=true;
    int t=0;string ans="\0";
    for(;i<len;i++)
    {
        if(!pan(s[i])) break;
        int tt=tent(s[i]);
        if(!ch[t][tt])
        {
            ff=false;
            break;
        }
        ans+=s[i];
        t=ch[t][tt];
    }
    if(ff && flag[t] && !f[seg[t]])
    {
        f[seg[t]]=true;
        work(seg[t]);
        f[seg[t]]=false;
		cout<<s[i];
    }
    else
    {
        cout<<ans;
		cout<<s[i];
    }
}

程序最后的195行和main里面127的换行都无法输出,在尝试直接在这个地方输出2等常量字符也无法输出

使用样例由考试第三个样例改变: 4 #define A A B C #define B{xxx} #define C yyy A {B} {A}

求大佬帮助

2022/4/21 20:15
加载中...