NOJ [1369] A Breaking Computer

  • 问题描述
  • Oh my god.My computer is break.When I writing something,the home and the end always is working.But I also write too quakily,
    even I don't see the screen.OK,when I finish a work ,can you tell me the work become in end?
    We modified the sample output, please check it.
  • 输入
  • This have some cases.
    Every case have a sentence(length< 200000 Include (A->Z a->z 0->9)).Then '[' is the home,']' is the end;
  • 输出
  • Input a sentence.

    Printf the finally sentence.


    卡在字符串全部是由'['    和 ']'构成的情况了,改了后就AC了

    //当遇到[时,把数字放到最前面,直到遇到]或者字符串结束

    #include<stdio.h>
    #include<string.h>

    bool vis[200010];
    char str[200010];
    int main()
    {
    while(~scanf("%s",str))
    {
    int len=strlen(str);
    bool st=false;
    int pos=len-1;
    memset(vis,0,sizeof(vis));
    for(int i=len-1;i>=0;i--)
    {
    if(str[i]!='[')
    {
    pos--;
    continue;
    }
    else
    {
    int temp=pos-1;
    vis[pos]=1;
    pos++;
    while(str[pos]!=']' && str[pos]!='\0' && str[pos]!='[')
    {
    printf("%c",str[pos]);
    vis[pos++]=1;
    }
    if(str[pos]==']')
    vis[pos]=1;
    pos=temp;
    }
    }
    for(int i=0;i<len;i++)
    if(!vis[i] && str[i]!=']' && str[i]!='[')
    printf("%c",str[i] );
    printf("\n");
    }
    return 0;
    }


你可能感兴趣的:(NOJ [1369] A Breaking Computer)