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那部分,因为考虑到自己要换 ...
随机推荐
- ListView 多行拖拽排序
核心代码:修改ListView的属性,及绑定事件 // 初始化listView1. private void InitializeListView() { listView1.AllowDrop = ...
- 【oneday_onepage】——Growth Is A Bitch
Companies are worth a multiple of their earnings and that multiple is directly related to earnings g ...
- java jdbc preparedstatement 分析
https://blog.csdn.net/xiong9999/article/details/54137326
- QTcpSocket 发送和接收数据的几种方法
1.QTcpSocket 继承于QAbstractSocket继承于QIODevice 2.QTcpSocket 提供的几种接收和发送数据方法 write ( const char *, qint64 ...
- Ogre2.0 全新功能打造新3D引擎
不知当初是在那看到,说是Ogre2.0浪费了一个版本号,当时也没多想,以为没多大更新,一直到现在想做一个编辑器时,忽然想到要看下最新版本的更新,不看不知道,一看吓一跳,所以说,网络上的话少信,你不认识 ...
- JDBC Statements, PreparedStatement和CallableStatement语句
当获得了与数据库的连接后,就可以与数据库进行交互了. JDBC Statement,CallableStatement和PreparedStatement接口定义了可用于发送SQL或PL/SQL命令, ...
- 数据抓取的艺术(三):抓取Google数据之心得
本来是想把这部分内容放到前一篇<数据抓取的艺术(二):数据抓取程序优化>之中.但是随着任务的完成,我越来越感觉到其中深深的趣味,现总结如下: (1)时间 时间是一个与抓取规模相形而 ...
- CI框架 -- 核心文件 之 Input.php(输入数据处理文件)
class CI_Input { //用户ip地址 protected $ip_address = FALSE; //用户浏览器地址 protected $user_agent = FALSE; // ...
- 使用Camera功能 AREA的理解
转至 http://blog.csdn.net/think_soft/article/details/7998478 使用Camera功能 大多数的Camera功能都是使用Camera.Paramet ...
- Keystone中间件WSGI环境变量总结
OpenStack keystonemiddleware接收前一个WSGI过滤器传来的WSGI环境信息,进行验证工作后传递给下一个中间件,本文探讨keystone中间件究竟有哪些WSGI环境变量. 说 ...