先按单面值累加,剩下的全用1元补足:
import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] v = {0, 1, 3, 8, 18, 38, 88, 188}; //先按单面值累加 for(int i = v.length - 1; i >= 0; --i){ if(n >= v[i]){ System.out.printf("%d %d", i, i + n - v[i]); //剩下的全用1元补足 return; } } } }