Fork me on GitHub

NYOJ题目816它合法吗?

-----------------------------------------------------

AC代码:

 1 import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4 
 5 public class Main {
 6     
 7     public static void main(String[] args) throws IOException {
 8         
 9         BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
10         
11         boolean first=true;
12         while(first || reader.ready()){
13             first=false;
14             
15             String s=reader.readLine();
16             System.out.println(solve(s)?"Yes":"No");
17         }
18         
19     }
20     
21     public static boolean solve(String s){
22         char cs[]=s.toCharArray();
23         if(cs[0]!='_' && !Character.isLetter(cs[0])) return false;
24         for(int i=1;i<cs.length;i++){
25             if(!Character.isLetterOrDigit(cs[i]) && cs[i]!='_') return false;
26         }
27         return true;
28     }
29 
30 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=816

posted @ 2016-08-31 09:37  CC11001100  阅读(156)  评论(0编辑  收藏  举报