Hello, i have been experiencing issues with a simple problem from SPOJ website.
Sphere Online Judge (SPOJ) - Problem NDIGITS
This is the code im working on.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void contador(short t[], int n)
{
int i;
if(n == 1)
t[0] = 10;
else
{
t[0] = 9;
for (i = 0; i < n ;i++)
t[i+1] = 0;
}
}
int main()
{
int n , i , d , m;
short t[999];
scanf(" %d ",&n);
for(i = 0;i < n ;i++)
{
scanf(" %d ",&d);
contador(t, d);
if(n == 0)
printf(" %d ", 0);
else
for (m = 0; m < d; m++)
printf(" %d ", t[m]);
printf(" \n ");
}
return 0;
}
The solution itself isnt a big deal but given the amount of digit to look for it can become an issue.
Basically i made an array of X amount of space (in this case 1000) and i filled it with a y amount of spaces with 0s, except the first space array[0] which will remain unchanged in (almost) all the cases.
There is no way to save numbers with 50,60 or even a lot more in a variable so the only thing i could do was make an array and simply save every digit in a space and just print it out one by one. The problem is, according to the judge, the answer is wrong. I donīt know why, i want to, i keep changing it over and over again and now instead of programming im just trying to guess.
Hope you guys can help me out here and thanks in advance.