360笔试
苦逼 最后5分钟断网 死活登不上去了 不知道第二道编程提交成功没有 倒霉的人
第一题AC
import java.util.Scanner; import java.util.regex.Pattern; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int i = scanner.nextInt(); String[] strings = new String[i]; for (int j = 0; j < i; j++) { strings[j] = scanner.next(); } int count = count(strings); System.out.println(count); } private static int count(String[] strings) { int num = 0; for (String string : strings) { if (Pattern.matches("[a-zA-Z]+", string) && string.length() <= 10) { num++; } } return num; } }第二题 不知道是不是AC 最后断网没看到结果 idea上测试是OK的(苦逼ing)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String s1 = scanner.nextLine(); String[] strings = s1.split(" "); int N = Integer.parseInt(strings[0]); int M = Integer.parseInt(strings[1]); String s2 = scanner.nextLine(); String[] strings2 = s2.split(" ", M); String res = change(N, M, strings2); System.out.println(res); } private static String change(int n, int m, String[] strings2) { String[] str = new String[n]; for (int i = 0; i < n; i++) { str[i] = String.valueOf(i + 1); } for (String s : strings2) { if (s.equals("1")){ String temp = str[0]; for (int i = 0; i < str.length-1; i++) { str[i] = str[i+1]; } str[str.length-1] = temp; }else { str = swap(str); for (int i = 0; i < str.length; i++) { str[i] = str[i]; } } } StringBuilder stringBuilder = new StringBuilder(); for (String s : str) { stringBuilder.append(s+" "); } return stringBuilder.toString(); } private static String[] swap(String[] strings1) { for (int i = 0; i <= strings1.length/2; ) { if (strings1[i].equals("")){ continue; } String temp = strings1[i]; strings1[i] = strings1[i+1]; strings1[i+1] = temp; i+=2; } return strings1; } }