微众银行4月8日笔试题目及部分代码
第一题忘了拍,大致是n个朋友m个礼物,要求均分礼物,(1)可以花a元送红包打发走一位朋友;(2)花b元再买一件礼物,两种操作可以混着用,要求输出打发所有朋友的最小花费,感觉很简单但是就是只过了91%。
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); int m = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); if(n <= m){ System.out.println(0); return; } long res = 0; res = Math.min(a,b) * (n - m); System.out.println(res); } }第二题
AC,大致思路就是算一下该字符串能组成的最大回文长度,然后按差值奇偶性输出胜利者,本来以为“最优策略”的删除任意一个字符会很复杂,但是试了下就过了。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.nextLine()); for(int i = 0;i < t;i++){ String word = sc.nextLine(); int n = word.length(); int len = huiLen(word); int num = Math.abs(len - n); if(num == 0){ System.out.println("Cassidy"); }else if(num % 2 == 0){ System.out.println("Cassidy"); }else{ System.out.println("Eleanore"); } } } public static int huiLen(String str) { int[] cnt = new int[58]; for(char c : str.toCharArray()){ cnt[c - 'A']++; } int res = 0; for(int i = 0;i < 58;i++){ res += cnt[i] - (cnt[i] & 1); } return res < str.length() ? res + 1 : res; } }第三题
递归模拟只过了18%,不会写,蹲一波大佬们的思路。
选择题做的凑合吧也感觉不出来,至今没面试过的菜鸡仍然许愿有面试