I'm getting wrong answer for some reason. I can not find the problem. When I run it on my machine it produces the correct answer. Can you help me find the reason behind the wrong answer?
/*
Author: Platon-Nikolaos Kiorpelidis
Purpose: Solution to problem "ACODE" from Sphere Online Judge
Date: 24-6-2016
Language: C++
Problem definition: For each input set, output the number of possible decodings for the input string. A = 1, B = 2, .. , Z = 26.
*/
#include <iostream>
#include <cstdint>
using namespace std;
uint32_t possible_decodings(void *array, uint32_t array_size)
{
uint16_t *subproblems = NULL;
subproblems = new uint16_t[array_size + 1];
for(size_t i = 0; i < array_size; i++)
subproblems[i] = 0;
subproblems[0] = 1;
size_t counter = 1;
subproblems[counter] = subproblems[counter - 1];
counter++;
while(counter < array_size + 1)
{
if( ( ( ((uint16_t*)array) [counter - 2] * 10 ) + ((uint16_t*)array) [counter - 1] ) <= 26)
subproblems[counter] = subproblems[counter - 2] + subproblems[counter - 1];
else if( ( ( ((uint16_t*)array) [counter - 2] * 10 ) + ((uint16_t*)array) [counter - 1] ) > 27)
subproblems[counter] = subproblems[counter - 1];
counter++;
}
cout << subproblems[array_size] << endl;
delete [] subproblems;
}
int main(int argc, char const *argv[])
{
uint16_t *sequence = NULL;
uint32_t num_elems = 1;
char c;
while(true)
{
num_elems = 1;
c = getchar();
if(c == '0')
break;
while(c != '\n')
{
num_elems++;
sequence = (uint16_t*)realloc(sequence, sizeof(uint16_t) * num_elems);
sequence[num_elems - 2] = c - '0';
c = getchar();
}
sequence[num_elems - 1] = '\0';
if(num_elems == 2)
cout << "1" << endl;
else
possible_decodings(sequence, num_elems - 1);
delete [] sequence;
sequence = NULL;
}
return(EXIT_SUCCESS);
}