Skip to content

Instantly share code, notes, and snippets.

@victorsenam
Created May 8, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorsenam/55a1b21300ea048830db to your computer and use it in GitHub Desktop.
Save victorsenam/55a1b21300ea048830db to your computer and use it in GitHub Desktop.
problema
#include <stdio.h>
#include <math.h>
int size(int n)
{
int i = 0;
while(n > 0)
{
i++;
n /= 10;
}
return i;
}
void searchMax(int n, int d, int num)
{
if (d == 0) printf("%d\n", num);
else
{
int i, aux, k, maxD, maxIndex;
aux = num/((int)pow(10, n-d-1));
maxD = aux%10;
maxIndex = i = 0;
printf("%d\n", aux);
while(aux > 0)
{
aux /= 10;
k = aux%10;
i++;
if (k > maxD)
{
maxD = k;
maxIndex = i;
}
}
printf("_%d %d %d %d %d\n", maxD, n-d-1+maxIndex, num, d, num%((int)pow(10, n-d-1+maxIndex)));
searchMax(n-d-1+maxIndex, d+1-maxIndex, num%((int)pow(10, n-d-1+maxIndex)));
}
}
int main(int argc, const char *argv[])
{
int n, d, num;
/* scanf("%d %d", &n, &d); */
/* scanf("%d", &num); */
n = 8;
d = 3;
num = 10735935;
searchMax(n, d, num);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment