-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphacode.cpp
More file actions
40 lines (36 loc) · 834 Bytes
/
alphacode.cpp
File metadata and controls
40 lines (36 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
char str[5002];
int main() {
scanf("%s",str);
while(str[0]!='0')
{
int len=strlen(str);
long long dp[len+1]={0};
/*base case*/
dp[0]=1;
int i=1; //i for index
while(i<len)
{
/*num is used to check if the
number formed using 2 digits is
valid character*/
int num=(str[i-1]-'0')*10;
num+=str[i]-'0';
/*checking for valid 1 digit number*/
if(str[i]-'0')
{
dp[i]=dp[i-1];
}
/*checking for two digit number*/
if(num>9 && num<=26)
{
dp[i]+=dp[i-2<0?0:i-2];
}
i++;
}
printf("%lld\n",dp[len-1]);
scanf("%s",str);
}
return 0;
}