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 }