DotNotation

DotNotation

Time Limit: 1000 ms 

Memory Limit: 65535 kB 

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

Sample 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 

Sample Output

Yes
Yes
No
Yes
Yes

 Source

UESTC


此题为一道涉及到编译原理的简单题,从式子<DotNotation> := <Number> | <DotNotation><Dots><Operator><Dots><Number>我们可以知道,合法标志是左结合的,即如果左边的字符串是一个标识符,那么我们可以先看左边标识符是否合法,不合法则整个标识符不合法,合法即检查后续的字符串,另外我们也很容可以看出来,合法标识符必须以数字开头结尾,至少包含一个'+''-''*''/'字符。

#include <cstdio>
 #include <cstring>
 
 const int max_l = 55;
 
 bool isDotNotation(char *str)
 {
 	int len = strlen(str);
 	if ( ( str[0] < '0' || str[0] > '9' ) || ( str[len - 1] < '0' || str[len - 1] > '9') )
 	{
 		return false;
 	}
 	int num = 0;
 	for ( int i = 1; i < len; ++i )
 	{
 		if ( str[i] == '.' )
 		{
 			continue;
 		}
 		if ( str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/' )
 		{
 			num++;
 			continue;
 		}
 		if ( str[i] < '0' || str[i] > '9' )
 		{
 			return false;
 		}
 		if ( str[i] >= '0' && str[i] <= '9' )
 		{
 			if ( num != 1 )
 			{
 				return false;
 			}
 			num = 0;
 		}
 	}
 	return true;
 }
 
 int main()
 {
 	int t;
 	char str[max_l];
 	FILE *fout;
 	fout = fopen("1.std.out", "w");
 	scanf("%d", &t);
 	getchar();
 	while ( t-- )
 	{
 		gets(str);
 		fprintf(fout, "%s\n", isDotNotation(str) ? "Yes" : "No");
 	}
 	return 0;
 }
 



> ggplot()+ + geom_histogram(binwidth = 200,data=data,aes(x=SII,y=..frequency..),alpha = 0.8,colour="gold3",fill="gold3")+ + scale_y_continuous(sec.axis = sec_axis(~.*4000, name = "HR (95%CI) for 2-year all-cause mortality"))+ + geom_line(data=HR, aes(SII,yhat/4000), + linetype="solid",size=1,alpha = 0.7,colour="steelblue1")+ + geom_ribbon(data=HR, + aes(SII,ymin = lower/4000, ymax = upper/4000), + alpha = 0.1,fill="blue")+ + theme_classic()+ + geom_hline(yintercept=1/4000, linetype=2,size=1)+ + geom_vline(xintercept=570,size=1,linetype=2,color = '#d40e8c')+ + geom_vline(xintercept=1000,size=1,linetype=2,color = '#d40e8c')+#查表HR=1对应的age + labs(x="Systemic immune-inflammation index", y="Density")+ + xlim(0,4000)+ + labs(title = " ")+ + theme(plot.title = element_text(hjust = 0.5)) Error in `geom_histogram()`: ! Problem while mapping stat to aesthetics. ℹ Error occurred in the 1st layer. Caused by error in `map_statistic()`: ! Aesthetics must be valid computed stats. ✖ The following aesthetics are invalid: ✖ `y = ..frequency..` ℹ Did you map your stat in the wrong layer? Run `rlang::last_error()` to see where the error occurred. Warning messages: 1: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. ℹ Please use `linewidth` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 2: The dot-dot notation (`..frequency..`) was deprecated in ggplot2 3.4.0. ℹ Please use `after_stat(frequency)` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 3: Removed 70 rows containing non-finite values (`stat_bin()`).
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值