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那部分,因为考虑到自己要换 ...
随机推荐
- JVM垃圾回收算法(最全)
JVM垃圾回收算法(最全) 下面是JVM虚拟机运行时的内存模型: 1.方法区 Perm(永久代.非堆) 2.虚拟机栈 3.本地方法栈 (Native方法) 4.堆 5.程序计数器 1 首先的问题是:j ...
- [转]C# RichTextBox不用滚动条
转自:http://blog.csdn.net/happy09li/article/details/7444912 第一种思路: richTextBox1.ScrollBars = RichTextB ...
- LibGDX skins
https://github.com/czyzby/gdx-skins ———————————————————————————————————————————— LibGDX comes with a ...
- [Qt] 利用QtWebKit完成JavaScript访问C++对象
一. 介绍 在浏览器扩展或者WebApp的项目经常用的脚本语言javascript有很多局限性,比如,javascript语言不能够夸窗口访问js对象,不能直接读写磁盘文件(这个也正是发明人设计的安全 ...
- Mac 系统上安装Lua和SubmlimeText 编译器
第一步:安装命令 curl -R -O http://www.lua.org/ftp/lua-5.2.3.tar.gz tar zxf lua-5.2.3.tar.gz cd lua-5.2.3 ma ...
- QMDP-Net: Deep Learning for Planning under Partial Observability
一篇用deep neural network做POMDP的论文
- Apache Flume 学习
Apache Flume,又称Flume NG (next generation),前身是Cloudera公司的Flume项目 -- 又称Flume OG. 这货的功能就是从源中将数据收集到指定的目的 ...
- 第三百五十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—数据收集(Stats Collection)
第三百五十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—数据收集(Stats Collection) Scrapy提供了方便的收集数据的机制.数据以key/value方式存储,值大多是计数 ...
- <<、|=、&的小例子
1. << 移位符 0x1 << 1 表示向左移1位 0x1二进制为:0001 左移1位:0010 效果: 2. | 按位或运算, & 按位与运算 enum STAU ...
- TCP/IP,http,socket,长连接,短连接——小结(转)
概要: 之前对这几个概念有点糊涂,查阅了些资料,稍微概括下他们的区别吧.如有错误,请拍~~~ 先看图: TCP/IP是什么? TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. 在 ...