Can someone explain what's the code is trying to do!

Please explain clearly! (:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
int a[10];

 void inc(int val) {
	for (int i = 0; i < 10; i++)
		a[i] += val;
}

int solve() {
int pow = 1;
	for (int len = 1; len <= 10; len++) {
		for (int digit = 1; digit <= 9; digit++) 
			if (a[digit] <= 0) {
				int res = digit;
				inc(1);
				a[digit]--;
				for (int d = 2; d <= len; d++) {
					for (int i = 0; i <= 9; i++) 
						if (a[i] <= 0) {
							res = res * 10 + i;
							inc(1);
							a[i]--;
							break;
						}
				}
				return res;
			}
		inc(-1);
		pow *= 10;
		if (a[0] < 0)
			return pow;
	}
	return -1/0;
}
Last edited on
Topic archived. No new replies allowed.