Simply Syntax(思维)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 5551 | Accepted: 2481 |
Description
0.The only characters in the language are the characters p through z and N, C, D, E, and I.
1.Every character from p through z is a correct sentence.
2.If s is a correct sentence, then so is Ns.
3.If s and t are correct sentences, then so are Cst, Dst, Est and Ist.
4.Rules 0. to 3. are the only rules to determine the syntactical correctness of a sentence.
You are asked to write a program that checks if sentences satisfy the syntax rules given in Rule 0. - Rule 4.
Input
Output
Sample Input
Cp
Isz
NIsz
Cqpq
Sample Output
NO
YES
YES
NO
题解:
0,p~z每个字母都是合法的句子
1, 如s是一个合法的句子,那么Ns也是一个合法的句子
2,如果s与t都是合法的一个句子,那么Cst, Dst, Est, and Ist.
3,只有满足以上的才是一个合法的句子
想的太多了,其实就按照所说的递归就好:
代码:
package com.hbc.week3;
import java.util.Scanner;
public class SimplySyntax {
private static Scanner cin = null;
static{
cin = new Scanner(System.in);
}
static boolean judge(String s){
char c = s.charAt(0);
if(s.length() == 1){
if(c >= 'p' && c <= 'z')
return true;
else
return false;
}
if(c == 'N'){
if(judge(s.substring(1))){
return true;
}
return false;
}
if(c == 'C'
|| c == 'D'
|| c == 'E'
|| c == 'I'){
for(int i = 2; i < s.length(); i++){
if(judge(s.substring(1, i)) && judge(s.substring(i, s.length()))){
return true;
}
}
return false;
}
return false;
}
public static void main(String[] args) {
//System.out.println(isSimpleSentence("pqp"));
while(cin.hasNext()){
String s = cin.next();
if(judge(s)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
Simply Syntax(思维)的更多相关文章
- POJ 1126:Simply Syntax
Simply Syntax Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5264 Accepted: 2337 Des ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 【Static Program Analysis - Chapter 2】 代码的表征之抽象语法树
抽象语法树:AbstractSyntaxTrees 定义(wiki): 在计算机科学中,抽象语法树(abstract syntax tree或者缩写为AST),或者语法树(syntax tree),是 ...
- Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)
1, http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-c 2, Introduction ...
- Nginx - Configuration File Syntax
Configuration Directives The Nginx configuration file can be described as a list of directives organ ...
- 13.1.17 CREATE TABLE Syntax
13.1.17 CREATE TABLE Syntax 13.1.17.1 CREATE TABLE ... LIKE Syntax 13.1.17.2 CREATE TABLE ... SELECT ...
- ES6 new syntax of Arrow Function
Arrow Function.md Arrow Functions The basic syntax of an arrow function is as follows var fn = data ...
- Active Directory: LDAP Syntax Filters
LDAP syntax filters can be used in many situations to query Active Directory. They can be used in VB ...
- vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)
vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...
随机推荐
- flume1.8实现hdfsSink整点滚动文件
由于官方的1.8版本hdfs-sink不能在每天的0点滚动文件,所以修改了flume-hdfs-sink源码. flume-hdfs-sink中修改了HDFSEventSink.java文件,其他文件 ...
- iOS第三方支付集成
支付宝(alipay)和微信支付(Wechat Pay) 支付宝: 一.总体流程 (1)先与支付宝签约.获得商户ID(partner)和账号ID(seller)(注冊app⽤用) (2)下载对应的公钥 ...
- Pass的通用指令开关
LOD: 设置:单个设置Shader.maximumLOD.全局设置Shader.globalMaximumLOD.QualitySettings里面的Maximum LODLevel 原理:小于指定 ...
- mybatis example 使用AND 和OR 联合查询
mybatis example 使用AND 和OR 联合查询 ViewPsmsgconsultExample example=new ViewPsmsgconsultExample(); ViewPs ...
- springmvc访问静态资源出现Request method 'GET' not supported
答案最后.:D 默认的访问的URL都会被DispatcherServlet所拦截. 这里说一下如何配置springmvc访问静态文件. <mvc:default-servlet-handler/ ...
- WebRTC网关服务器单端口方案实现
标准WebRTC连接建立流程 这里描述的是Trickle ICE过程,并且省略了通话发起与接受的信令部分.流程如下: 1) WebRTC A通过Signal Server转发SDP OFFER到Web ...
- easyui datagrid设置fit: true后,页面显示不全的情况
跟工具栏有关 <div id="tb"> <div style="float:left;"> <a href="#&qu ...
- Java 代理使用及代理原理
今天再测试Socket编程时,无法连接外网.公司用的是Http的代理.上网搜索也没看太懂,所以花了大量时间来学习.看了HTTP和TCP协议的关系好,才有所明白.现在能通过Socket使用HTTP代理了 ...
- Q_UNUSED() 方法的使用
Q_UNUSED() 没有实质性的作用,用来避免编译器警告 //比如说 int testFunc(int a, int b, int c, int d) { int e; return a+b+c; ...
- MySql折腾小记二:text/blog类型不允许设置默认值,不允许存在两个CURRENT_TIMESTAMP
From: http://www.cnblogs.com/cyq1162/archive/2011/05/17/2049055.html 在 CYQ.Data 数据框架的反向工程中,遇到MySQL的问 ...