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