AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#define LL long long
using namespace std;
int a[1010] = {0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6};
int main() {
int n;
cin>>n;
int temp;
int ans = 0;
a[30] = 6;
a[40] = 5;
a[50] = 5;
a[60] = 5;
a[70] = 7;
a[80] = 6;
a[90] = 6;
a[1000] = 11;
for(int j = 20;j < 100;j += 10){
for(int i = j+1;i <= j+9;i++){
a[i] = a[j] + a[i-j];
}
}
int hundred = 7;
for(int i = 100;i < 1000;i += 100){
a[i] = a[i/100] + 7;
}
for(int i = 101;i < 1000;i++){
if(i % 100 != 0){
int mm = i/100 * 100;
a[i] = a[mm] + a[i-mm] + 3;
}
}
for(int i = 1;i <= n;i++){
scanf("%d",&temp);
ans += a[temp];
printf("%d\n",ans);
}
return 0;
}