#include <stdio.h>
int decode(char* message, size_t len) {
int i, w, ways[] = { 1, 0 };
for(i = 0, w; i < len; ++i) {
w = 0;
if((i > 0) && ((message[i - 1] == '1') || (message[i - 1] == '2' && message[i] < '7'))) {
w += ways[1];
}
if(message[i] > '0') {
w += ways[0];
}
ways[1] = ways[0];
ways[0] = w;
}
return ways[0];
}
int main(void) {
printf("%d\n", decode
("1090", 4)); printf("%d\n", decode
("12321", 5)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgZGVjb2RlKGNoYXIqIG1lc3NhZ2UsIHNpemVfdCBsZW4pIHsKICAgIGludCBpLCB3LCB3YXlzW10gPSB7IDEsIDAgfTsKICAgIGZvcihpID0gMCwgdzsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgdyA9IDA7CiAgICAgICAgaWYoKGkgPiAwKSAmJiAoKG1lc3NhZ2VbaSAtIDFdID09ICcxJykgfHwgKG1lc3NhZ2VbaSAtIDFdID09ICcyJyAmJiBtZXNzYWdlW2ldIDwgJzcnKSkpIHsKICAgICAgICAgICAgdyArPSB3YXlzWzFdOwogICAgICAgIH0KICAgICAgICBpZihtZXNzYWdlW2ldID4gJzAnKSB7CiAgICAgICAgICAgIHcgKz0gd2F5c1swXTsKICAgICAgICB9CiAgICAgICAgd2F5c1sxXSA9IHdheXNbMF07CiAgICAgICAgd2F5c1swXSA9IHc7CiAgICB9CiAgICByZXR1cm4gd2F5c1swXTsKfQoKaW50IG1haW4odm9pZCkgewogICAgcHJpbnRmKCIlZFxuIiwgZGVjb2RlKCIxMDkwIiwgNCkpOwogICAgcHJpbnRmKCIlZFxuIiwgZGVjb2RlKCIxMjMyMSIsIDUpKTsKICAgIHJldHVybiAwOwp9