Hi,
The below solution for the strange WACA is found working for me.
But while submitting it shows "Wrong Solution" while compiling for GCC (5.1).
Kindly help on this!!
include
include
include
include
unsigned long long int rangecheck(unsigned long long int num)
{
unsigned long long int temp = num;
unsigned long long int count =0;
char st[1000];
memset(&st, 0, 1000);
unsigned long long int index1, index2;
while (temp)
{
count ++;
strcat(st, "1");
temp = temp/10;
}
index1 = atoi(st);
strcat(st, "1");
index2 = atoi(st);
if(abs(num - index1) > abs(num -index2))
return index2;
else
return index1;
}
int main()
{
unsigned long long int num =0, index=0, oper = 0, temp = 0, total = 0;
unsigned int array = 0, i;
scanf("%d", &array);
unsigned long long int output[array];
unsigned long long int input[array];
memset(&input, 0, array);
memset(&output, 0, array);
for (i = array; i > 0; i--)
{
index=0, oper = 0, temp = 0, total = 0;
scanf("%llu", &input[i]);
temp= num = input[i];
while(temp > 0)
{
temp = num -total;
index = rangecheck(temp);
if (index < temp)
{
total = total + index;
oper++;
if(total < num)
temp = num - total;
}
else
{
total = total + index;
if(total >= num)
{
temp = total - num;
oper++;
while (total > num)
{
index = rangecheck (temp);
total = total - index;
temp = total - num;
oper++;
while (total < num)
{
temp = num - total ;
index = rangecheck (temp);
total = total + index;
temp = num - total ;
oper++;
}
}
}
}
}
output[i] = oper-1;
}
printf("Input\r\n");
printf("%d\r\n", array );
for (i = array; i > 0; i--)
printf("%llu\r\n", input[i] );
printf("Output\r\n");
for (i = array; i > 0; i--)
printf("%llu\r\n", output[i] );
return 0;
}