今晚度小满第一题,大佬们能不能帮我看看哪里错了
用切割字符的方法比较的,只AC到18,感觉思路没问题呀。。
import java.math.BigDecimal; import java.util.*; public class Main { public static void emoji(BigDecimal[] arr){ for (int i = 0; i < arr.length; i++) { BigDecimal num = arr[i]; String str = String.valueOf(num); for (int j = 1; j < str.length(); j++) { char temp = result(str,j); if (temp == 'G' && j == str.length()-1) { System.out.println("G"); break; } if (temp == 'H') { System.out.println("H"); break; } else if(j == str.length()-1){ System.out.println("S"); break; } } } } public static char result(String s,int i){ int count = 0; int res = 0; BigDecimal big = new BigDecimal(Integer.valueOf(s)); for (int j = 0; j+i < s.length()+1; j++) { res++; int temp = Integer.parseInt(s.substring(j,j+i)); BigDecimal small = new BigDecimal(temp); try { big.divide(small); count++; } catch (ArithmeticException e) { if (count > 1) count = 1; } } if (count == res) return 'G'; else if (count == 0) return 'S'; return 'H'; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); if (n < 1 || n > 100) return; BigDecimal[] arr = new BigDecimal[n]; BigDecimal d1 = new BigDecimal(1); BigDecimal d2 = new BigDecimal(Math.pow(10,12)); try { for (int i = 0; i < n; i++) { arr[i] = new BigDecimal(in.nextLine()); if (arr[i].compareTo(d1)<0 || arr[i].compareTo(d2) > 0) return; } } catch (Exception e){ return; } in.close(); emoji(arr); } }