NOJ [1369] A Breaking Computer

本文介绍了一种处理字符串中特殊字符'[', ']'的方法,通过调整字符位置来解决问题。该方法适用于当字符串由这些特殊字符组成时的特殊情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 问题描述
  • 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;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值