C语言合法标识符
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 60915 Accepted Submission(s): 24074
Problem Description
输入一个字符串,判断其是否是C的合法标识符。
Input
Output
Sample Input
3 12ajf fi8x_a ff ai_2
Sample Output
no yes no
import java.util.Scanner; public class reg_hdu2024 { public static void main(String[] args) { Scanner sc = new Scanner(system.in); int t = sc.nextInt(); sc.nextLine(); while(t-->0){ String str = sc.nextLine(); String reg = "\\b[a-zA-Z_]\\w*"; boolean boo = str.matches(reg); if(boo){ System.out.println("yes"); }else{ System.out.println("no"); } } } }
只能说这个题目出得好哇,可以学习最基本的正则表达式用法,还可以写blog水积分