-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACODE.cpp
More file actions
62 lines (59 loc) · 1.14 KB
/
ACODE.cpp
File metadata and controls
62 lines (59 loc) · 1.14 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// https://www.spoj.com/problems/ACODE/
#include<bits/stdc++.h>
using namespace std;
string A;
long long int D[5005];
long long int c;
void Fun(int n,int p)
{
if(p+1==A.size()||p==A.size())
{
}
else{
if((A[p+1]-'0')!=0){
if(D[p+1]==-1)
Fun(A[p+1]-'0',p+1);
D[p]=D[p+1];
}
if((A[p]-'0')*10+(A[p+1]-'0')<=26&&A[p+2]-'0'!=0)
{
if(D[p+2]==-1){
if(p+2<A.size())
Fun(A[p+2]-'0',p+2);
else
Fun(-1,p+2);
}
if(D[p]!=-1)
D[p]+=D[p+2];
else
D[p]=D[p+2];
}
//D[p]=D[p+1]+D[p+2];
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int S=5005;
while(1)
{
//string a;
cin>>A;
if(A.compare("0")==0)
break;
int l=A.size();
for(int i=0;i<S;i++)
D[i]=-1;
D[l]=1;
D[l-1]=1;
//c=0;
Fun(A[0]-'0',0);
if(D[0]!=-1)
cout<<D[0]<<"\n";
else
cout<<"0\n";
S=l+1;
}
}