-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACODE.cpp
More file actions
59 lines (59 loc) · 1.27 KB
/
ACODE.cpp
File metadata and controls
59 lines (59 loc) · 1.27 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
/*
===================================================
Name :- Nishant Raj
Email :- raj.nishant360@gmail.com
College :- Indian School of Mines
Branch :- Computer Science and Engineering
Time :- 18 August 2015 (Tuesday) 23:55
===================================================*/
#include <bits/stdc++.h>
#include <boost>
using namespace std;
#define ll long long
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define mod 1000000009
int cnt = 0 ;
bool valid(string &s){
if(s.size() <= 0)
return false;
if(s[0] == '0')
return false;
int val = stoi(s);
if(val >= 1 && val <= 26)
return true;
return false;
}
bool cou(string &s , int pos){
//total ++;
if(s.size() > 0&& s[0] == '0')
return false;
if(pos == s.size())
return true;
string x , y;
x = s.substr(pos , 1);
if(s.size() - pos >= 2)
y = s.substr(pos , 2);
if(valid(x) && cou(s , pos+1 , chk))
cnt++;
if(valid(y) && cou(s , pos+2 , chk))
cnt++;
return false;
}
int main(){
while(1){
cnt = 0;
string s;
cin>>s;
if(s[0] == '0')
return 0;
int chk[s.size() + 9];
for(int i = 0 ; i < s.size() ; i++)
chk[i] = -1;
cou(s , 0 , chk);
//cout<<total<<endl;
cout<<cnt<<endl;
}
return 0;
}