NotNotation(CDOJ1001坑爹题啊)

感觉只有CDOJ才会出这样坑爹的题,,,---数字只有一位,不是多位的。其实是一道简单题


#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<stack>
#include<math.h>
#include<stdlib.h>
#include<list>
#include<vector>

using namespace std;


int main()
{
    int i,j,k;
    char go[1999];
    int l;
    int t;
    cin>>t;
    int hi[100];
    int L;
    while (t--)
    {
        cin>>go;
        l=strlen(go);
        L=0;
        bool flag=true;
        if ( go[l-1]>'9'||go[l-1]<'0')
        {
            flag=false;
        }
        if (go[0]>'9'||go[0]<'0')
            flag=false;
        
        for (i=0;i<l;)
        {
            if (go[i]=='.')
            {
                while (go[i]=='.')
                    i++;
            }
            else if (go[i]>='0'&&go[i]<='9')
            {
                    i++;
                hi[L++]=1;
            }
            else if (go[i]=='*'||go[i]=='/'||go[i]=='-'||go[i]=='+')
            {
                i++;
                hi[L++]=2;
            }
            else
            {
                i++;
                flag=false;
            }
        }
        for (i=0;i<L;i++)
        {
            if (i&1)
            {
                if (hi[i]==1)
                    flag=false;
            }
            else
            {
                if (hi[i]==2)
                    flag=false;
            }
        }
        if (flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        
    }
}



Description

love8909最近在学一种新的表达式表示法,称之为<DotNotation>。定义如下:

<DotNotation> := <Number> | <DotNotation><Dots><Operator><Dots><Number>
<Dots> := "" | <Dots>"."
<Operator> := exactly one of "+-*/"
<Number> := exactly one of "0123456789"

这是一个递归的定义,即是说
单个的数字是<DotNotation>
在<DotNotation>后连接任意数量的”.”(<Dots>),然后连接一个操作符(<Operator>),再接上任意数量的”.”,最后再接一个数字,得到的还是还是一个<DotNotation>
比如说,"5"是一个<DotNotation>,如果在后面接上".+.7",你将得到另一个<DotNotation>, 如果你再在后面接上"*..3"得到"5.+.7*..3",这还是一个<DotNotation>。

可是love8909很纠结,因为他竟然不会判断一个<DotNotation>是否合法,你能帮帮他吗?

Input

第1行一个数T,表示测试数据组数
后面T行每行一个长度为L的字符串(1 <= L <= 50)

Output

T行,每一行,如果合法,输出”Yes”,反之输出”No”

Simple Input

5
3+5
9..+.5...*....3
5.3+4
9*9*9*9*9*9*9*9*9*9*9*9*9*9
3.........../...........4

Simple Output

Yes
Yes
No
Yes
Yes

Source

love8909


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值