The original question is as follows
C-Language legal identifiersTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 59747 Accepted Submission (s): 23638
Problem description Enter a string to determine whether it is a valid identifier for C. Input data contains multiple test instances, the first row of the data is an integer n, which indicates the number of test instances, followed by n rows of input data, each of which is a string of not more than 50 in length. Output outputs one row for each set of input data. If the input data is a valid identifier for C, output "yes", otherwise, output "no". Sample Input312ajffi8x_aff Ai_2 Sample Outputnoyesno Authorlcy
Import Java.util.scanner;public class Main {public static void Main (string[] args) {Scanner scan =new Scanner (system.in); int N, M;while (Scan.hasnext ()) {n = scan.nextint (); String c=scan.nextline ();//m = Scan.nextint (); while (n!=0) {n--; String s=scan.nextline (); int judge;if (S.matches ("[A-z_a-z][a-z_a-z0-9]{0,}") Judge=1;else judge=0;if (judge==1) SYSTEM.OUT.PRINTLN ("yes"), Else System.out.println ("no");}}}
This water problem mainly has two points to notice, one is the question which reads the space to need to use Scan.nextline (); the second is the use of matches
(Java implementation) Hangzhou electric oj2024c Language Legal identifier