L1-017 到底有多二 (15分)java

    技术2022-07-10  105

    L1-017 到底有多二 (15分)java

    输入样例

    -13142223336

    输出样例

    81.82% import java.util.Scanner; public class Main{ public static void main(String [] args){ Scanner input = new Scanner (System.in); String a = input.next(); char[] b = a.toCharArray(); int i,j =0; for(int i = 0; i < a.length(); i++) { if(b[i] == '2'){ j++; } } if(j == 0) { System.out.println("0.00%"); } if(b[0] == '-') { if((b[a.length()-1]) %2 == 0) { System.out.printf("%.2f%%", j * 1.5 * 2 *100 /(a.length()-1)); } else System.out.printf("%.2f%%", j * 1.5 *100 /(a.length()-1)); } else{ if((b[a.length()-1]) %2 == 0) { System.out.printf("%.2f%%", j * 2*100 /a.length()); } else System.out.printf("%.2f%%", j *100 /a.length()); } } }
    Processed: 0.010, SQL: 9