-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACODE.cpp
More file actions
54 lines (45 loc) · 701 Bytes
/
ACODE.cpp
File metadata and controls
54 lines (45 loc) · 701 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Problem : ACODE from SPOJ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(string s){
int l = s.length(),i,code;
ll dp[l][2];
for(i=0;i<l;i++){
if(i==0){
dp[i][0] = ((s[i]!='0')?1:0);
dp[i][1] = 0;
}
else{
code = (s[i-1]-'0')*10 + s[i]-'0';
if(s[i]=='0'){
dp[i][0] = 0;
}
else{
dp[i][0] = dp[i-1][0] + dp[i-1][1];
}
if(code>=10 && code<=26){
if(i==1){
dp[i][1] = 1;
}
else{
dp[i][1] = dp[i-2][0] + dp[i-2][1];
}
}
else{
dp[i][1] = 0;
}
}
}
cout<<(dp[l-1][0] + dp[l-1][1])<<"\n";
return ;
}
int main(){
string s;
cin>>s;
while(s!="0"){
solve(s);
cin>>s;
}
return 0;
}