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那部分,因为考虑到自己要换 ...
随机推荐
- Selenium (4) —— Selenium是什么? WebDriver是什么?做什么?(101 Tutorial)
Selenium (4) -- Selenium是什么? WebDriver是什么?做什么?(101 Tutorial) selenium版本: v2.48.0 (Standalone Seleniu ...
- 十大要避免的Ext JS开发方法
原文地址:http://www.sencha.com/blog/top-10-ext-js-development-practices-to-avoid/ 作者:Sean LanktreeSean i ...
- Shell数组遍历
#!/bin/bash emp_info=( aaa aaa@qq.com bbb bbb@qq.com ccc ccc@qq.com ddd ddd@qq.com eee eee@qq.com ) ...
- QueenPuzzle-N皇后问题
详见-算法之美-p180. #include <iostream> #include <memory.h> #include <conio.h> #include ...
- 使用javascript实现浏览器全屏
HTML 5中的full screen,目前可以在除IE和opera外的浏览器中使用 ,有的时候用来做 全屏API,游戏呀,等都很有用.先看常见的API 1 element.requestFullSc ...
- 自然语言交流系统 phxnet团队 创新实训 项目博客 (九)
项目技术总结: VoiceToText的具体使用方法: 语音转文本部分是调用的科大讯飞的在线语音,它的激发方式是按键,通过按钮触发开启安卓设备的录音,此部分需要在源码中写入关于安卓权限的要求,来调用安 ...
- java 正则表达式 验证字符串 只包含汉字英文数字
String content = “testContent”; String regex="^[a-zA-Z0-9\u4E00-\u9FA5]+$"; Pattern patter ...
- 关于Unity中的3D拾取
3D拾取 3D游戏实际上看到的是2D画面,我们在屏幕上点击,想要找到哪个3D物体,我们实际上是在一个2维平面内做3D拾取. 3D拾取实际上是,当玩家点击屏幕的时候,会从显示屏幕的摄像头发射一条射线,射 ...
- 【转】【Python】Python网络编程
Socket简介 在网络上的两个程序通过一个双向的通信连接实现数据的交换,这个链接的一端称为一个Socket(套接字),用于描述IP地址和端口. 建立网络通信连接至少要一对端口号(Socket),So ...
- HTML5实现摇一摇的功能(实测后)--转
eviceMotionEvent(设备运动事件)返回设备有关于加速度和旋转的相关信息.加速度的数据将包含三个轴:x,y和z(示意如下图所 示,x轴横向贯穿手机屏幕或者笔记本键盘,y轴纵向贯穿手机屏幕或 ...