为什么第二题这样子写就81?是有啥答案没考虑到 a = int(input()) k = input() list_data = k.split(' &(30184)#39;) su = 0 flag = 0 for i in range(0, len(list_data)): if list_data[i] == '0&(30533)#39;: flag += 1 list_data[i] = '1' su += int(list_data[i]) if su == 0: flag += 1 print(flag)
第四题 import java.util.Scanner; public class Main { static int[] pow10 = new int[10]; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int k = 1; for(int i = 0;i < 10;i++) { pow10[i] = k; k *= 10; } for(int i = 0;i < n;i++) System.out.print(getNum(in.nextInt(),m) + " "); } public static int getNum(int w,int m){ if(w == 0 || w%m == 0) return 0; if(m-w == 1) return 1; int min = Integer.MAX_VALUE; for(int i = 0;i < 10;i++){ int dist = w+pow10[i]; if(dist < m) dist = dist; else if(dist%m == 0) dist = m; else if(dist > m) dist = dist%m; if(dist <= w) continue; min = Math.min(min,getNum(dist,m)+1); } return min; } }