360笔试8月27日
第一题:合法名字
名字仅有大小写英文字母组成且长度不超过10,则认为合法,否则认为不合法
输入:
第一行,num 收到的问卷数量
接下来有n行,每行都由大小写、数字、下划线组成的字符串,
输出:有效问卷数量
样例:
输入:
5
BA
aCWVXARgUbJDG
OPPCSKNS
HFDJEEDA
ABBABBBBAABBBAABAAA
输出:3
public class Main01 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s = scanner.nextLine(); int num = Integer.parseInt(s); int result = 0; String regEx = "[a-zA-Z]"; // Pattern 作用在于编译正则表达式后创建一个匹配模式 Pattern pattern = Pattern.compile(regEx); for (int i = 0; i <num ; i++) { String line = scanner.nextLine(); // 名字长度不能超过10 if(line.length()>10){ continue; } if (line.contains("_") || line.contains("1") || line.contains("2") || line.contains("3") || line.contains("4") || line.contains("5") || line.contains("6") || line.contains("7") || line.contains("8") || line.contains("9") ) { continue; } } System.out.println(result); } }第二题:符合句子结构
样例:
输入:
3 3 3
i you he
am is are
yours his hers
5
i am yours
you is his
he are hers yours
i am am yours
is his
输出:
YES
YES
YES
NO
NO
public class Main02 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String numStr = in.nextLine(); String aStr = in.nextLine(); String bStr = in.nextLine(); String cStr = in.nextLine(); List<Boolean> result = new ArrayList<>(); // 第四个数字 int dNum = Integer.parseInt(in.nextLine()); for (int i = 0; i <dNum ; i++) { Boolean re = true; String line = in.nextLine(); String[] s = line.split(" "); for (int j = 0; j <s.length ; j++) { if(j==0){ if(!aStr.contains(s[j])){ re = false; } }else if(j==1){ if(!bStr.contains(s[j])){ re = false; } }else { if(!cStr.contains(s[j])){ re = false; } } } result.add(re); } for (Boolean aa:result) { System.out.println(aa?"YES":"NO"); } } }