Java内蒙创业

it2025-05-27  11

Problem A: 内蒙创业 Time Limit: 1 Sec Memory Limit: 128 MB

Description

莱特与瑞秋毕业了,他们决定在内蒙创业成立一家畜牧业公司,创业第一步:他们希望给公司里的每 一只羊一个编号。 编号的命名规则如下: . 长度为10 位; 2. 前两位必须为”LQ”; 3. 后八位必须为数字; 现在有若干个字符串,希望你写一个程序判断它是不是一个合法编号。

Input

第一行一个T(1≤T ≤20) 代表数据组数。 每组测试数据有一个字符串s(1 ≤|s|≤20),s 只包含数字和大写英文字母,代表等待判断的字符串。

Output

如果编号合法输出”YES”,否则输出”NO”。

Sample Input Copy

3 LQ12345678 LQ123 QL12345678

Sample Output Copy

YES NO NO

Java代码段:

import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { String s=sc.next(); if(s.length()!=10) { System.out.println("NO"); } else { char [] c=s.toCharArray(); int num=0; for(int i=2;i<10;i++) { if(c[i]<='9'&&c[i]>='0') //if(!c[i]>9&&!c[i]<0) 试下 num++; } if(c[0]!='L'||c[1]!='Q'||num!=8) System.out.println("NO"); else System.out.println("YES"); } } } }

运行结果: C语言代码:

运行结果:

END

最新回复(0)