fork(53) download
  1. #include <stdio.h>
  2.  
  3. int decode(char* message, size_t len) {
  4. int i, w, ways[] = { 1, 0 };
  5. for(i = 0, w; i < len; ++i) {
  6. w = 0;
  7. if((i > 0) && ((message[i - 1] == '1') || (message[i - 1] == '2' && message[i] < '7'))) {
  8. w += ways[1];
  9. }
  10. if(message[i] > '0') {
  11. w += ways[0];
  12. }
  13. ways[1] = ways[0];
  14. ways[0] = w;
  15. }
  16. return ways[0];
  17. }
  18.  
  19. int main(void) {
  20. printf("%d\n", decode("1090", 4));
  21. printf("%d\n", decode("12321", 5));
  22. return 0;
  23. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
0
6