自己试数据的时候发现大于11的最后几行会出现负数类似-2 0 -8 -3 -8 -5 -6 -1 -8 -5,这是怎么了
#include<bits/stdc++.h>
using namespace std;
int N, counter = 0, l[1000000];
int a[10] = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};
void measure(int total, int flag, int num){
if(flag == 10 && total == N) {
l[counter] = num;
counter++;
return;
}
if(flag == 10 && total < N) return;
for(int j = 1; j < 4; j++){
if(total+j > N) continue;
else{
if(num == 0) measure(total+j, flag+1, j);
else{
measure(total+j, flag+1, num*10+j);
}
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("friedChicken.in", "r", stdin);
freopen("friedChicken.out", "w", stdout);
#endif
cin >> N;
measure(0, 0, 0);
if(counter == 0) {
cout << 0 << endl;
return 0;
}
cout << counter << endl;
for(int j = 0; j < counter; j++){
for(int i = 0; i < 10; i++){
cout << l[j]/a[i] << " ";
l[j] = l[j]%a[i];
}
cout << endl;
}
}