微众银行笔试9.13
1.给n个数,取3个数拼接,输出最大数字
先取最长的三个数再字典序
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class _wz1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] arr = new String[n]; for (int i = 0; i<n; i++){ arr[i] = Integer.toString(sc.nextInt()); } Arrays.sort(arr, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.length() == o2.length() ? o2.compareTo(o1) : o2.length()-o1.length(); } }); String[] arr2 = new String[3]; arr2[0] = arr[0]; arr2[1] = arr[1]; arr2[2] = arr[2]; Arrays.sort(arr2, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o2.compareTo(o1); } }); for (int i = 0; i<3; i++){ System.out.print(arr2[i]); } } }
中途进的笔试,没时间写了,后面写完了代码过了样例不知道对不对
思路:先求a和b之间的倍数,再求这个倍数是多少个2,再将2的幂数除以3,2和1求得乘除8,4和2的次数
import java.util.Scanner; public class _wz2 { public static long log(long n) { long count = 0; if(n == 1) return 0; while(n > 1) { n = n>>1; //右移 -> 除以2的1次方 count++; } return count; } public static long Count(long a, long b,long ans){ if ((a>b ? a%b:b%a) != 0) return -1; long res = a>b ? a/b:b/a; //求倍率 long count = 0; if(res==1) return 0; if((res&1)==1) return -1; else res = log(res); //倍率换算成多少个2 // 统计变换次数 count += (res/3); res %= 3; count += (res/2); res %= 2; count += res; return count; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int i = 0; i<T; i++){ long a = sc.nextLong(); long b = sc.nextLong(); System.out.println(Count(a,b,0)); } } }