网易后端今晚笔试的有吗?
第一题试了几个用例,都没问题,只能过12.5,无法理解呢。。。而且这个输入输出必须带上“”有点奇葩
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ String s = scanner.nextLine(); String[] str = s.split(","); String s1 = str[0].substring(1,str[0].length()-1); String s2 = str[1].substring(1,str[1].length()-1); Double yuan = Double.parseDouble(s1)+Double.parseDouble(s2); String ss = yuan+""; StringBuilder res = new StringBuilder(); res.append('"'); if(yuan.intValue()-yuan==0) ss= yuan.intValue()+""; int n = ss.length(); int ca = 0; for (int i = n-1; i >= 0; i--) { char c = ss.charAt(i); if(c=='.'){ res.append("."); continue; } int tmp = ca+c-'0'; if(c=='0'){ tmp = ca+1; } res.append(tmp%9); ca = tmp/9; } if(ca!=0) res.append(ca); res.append('"'); System.out.println(res.reverse().toString()); } } }第二题也迷之卡60
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); if(n<=0){ System.out.println(0); continue; } int[] man = new int[n]; int[] project = new int[n]; for (int i = 0; i < n; i++) { man[i] = scanner.nextInt(); } for (int i = 0; i < n; i++) { project[i] = scanner.nextInt(); } int k = scanner.nextInt(); Arrays.sort(man); Arrays.sort(project); int count = 0; int res = 1; for (int i = n-1; i >= 0; i--) { if(man[i]>project[i]) count++; else if (man[i]<project[i]) count--; } if(count<0){ System.out.println(0); continue; }else{ for (int i = 1; i <= count; i++) { res *= i; } System.out.println(res%k); } } } }