#include <iostream>
using namespace std;
int NumDecodings(string s)
{
int len = s.length();
if (len == 0) return 0;
int ways[len+1];
ways[len] = 1;
ways[len-1] = s[len-1] == '0'? 0 : 1;
for (int i = len-2; i >= 0; --i)
{
char c0 = s[i];
if(c0 == '0')
{
ways[i] = 0;
continue;
}
ways[i] = ways[i+1];
char c1 = s[i+1];
if (c0 == '1'
|| (c0 == '0' && c1 != '0')
|| (c0 == '2' && c1 <= '6'))
ways[i] += ways[i+2];
}
return ways[0];
}
int main(int argc, char** argv)
{
cout << NumDecodings("11");
cout << NumDecodings("43719");
return 0;
}