NotNotation(CDOJ1001坑爹题啊)
  W79oLdECuAdO 2023年11月02日 125 0


感觉只有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



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: 因素分解方法数 下一篇: CF_353D (queue)
  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  Uw88jE728Bxt   2023年11月02日   322   0   0 #include子树ci
  vxoexqgjyiCS   2023年11月19日   17   0   0 i++linuxvim
  3n45YYmVLV9P   2023年11月13日   19   0   0 ico#includeLine