-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiggestNmbrWthSameDigits.c
More file actions
58 lines (53 loc) · 1.27 KB
/
BiggestNmbrWthSameDigits.c
File metadata and controls
58 lines (53 loc) · 1.27 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef long long lg_;
lg_ numPlaces (lg_ n) {
lg_ r = 1;
if (n < 0) n = -n;
while (n > 9) {
n /= 10;
r++;
}
return r;
}
long long next_bigger_number(long long n) {
lg_ ln = numPlaces(n); lg_ alr[(int) (pow(ln, 2)) ];
// ref arr
lg_ rf[ln];
//for (lg_ o=0;o<ln;o++){
// rf[o] = n / (int)(pow(10, ln-o));
//}
char temp[ln];
sprintf((char*)temp,"%lld",n);
for(int i =0; i<ln; i++)
rf[i] = temp[i];
//printf("%c",temp[i]);
// swap by indx [i] => [j]
int v = 0; // valids nmbrs
for (lg_ i = 0; i < ln; i ++){
lg_ p_a[ln];
for (lg_ j = i; j < ln; j ++){
lg_ k = 0; //swap on k=z
for (lg_ z = 0; z < ln; z ++){
if(z == k){p_a[z] = rf[i]; p_a[z + 1] = rf[z];
z++;
}else{
p_a[z] = rf[z];
}
}
k++;
}
for(lg_ x = 0; x < ln; x ++){
printf("%lld", p_a[x]);
}
printf("\n");
for(lg_ k = 0; k < (int) (pow(ln, 2)); k++){
//if(alr[k] == p_a){break;}
}
//alr[v] = p_a;
v++;
}
return 21; //insert code here
}