(Java implementation) Hangzhou electric oj2024c Language Legal identifier

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.