rohitnandwate
BAN USER#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class alphaCodes {
int convertToInt(string s);
bool isValidLetter(int n);
void printCode(char* a, int k);
void backtrack(char* a, int k, string input, int s, int& count);
public:
void printAllCodes(string input);
char getLetter(int n);
};
void alphaCodes::printAllCodes(string input) {
char* a = new char[input.length() + 1];
int k = 0;
int s = 0;
int count = 0;
backtrack(a, k, input, s, count);
cout << "Count:" << count << endl;
}
int alphaCodes::convertToInt(string s){
int val;
istringstream ( s ) >> val;
return val;
}
char alphaCodes::getLetter(int n) {
return (n-1) + 'a';
}
bool alphaCodes::isValidLetter(int n) {
return (n > 0 && n < 27);
}
void alphaCodes::printCode(char* a, int k){
for (int i=0; i < k; ++i){
cout << a[i];
}
cout << endl;
}
void alphaCodes::backtrack(char* a, int k, string input, int s, int& count) {
if(s == input.length()){
printCode(a, k);
count++;
}
else {
int n = convertToInt(input.substr(s, 1));
if(isValidLetter(n)){
a[k] = getLetter(n);
backtrack(a, k+1, input, s+1, count);
}
if(s+1 < input.length()){
n = convertToInt(input.substr(s,2));
if(isValidLetter(n)){
a[k] = getLetter(n);
backtrack(a, k+1, input, s+2, count);
}
}
}
}
int main(int argc, char** argv) {
if (argc < 2){
cout << "Please enter an input number string!" << endl;
return 0;
}
alphaCodes a;
a.printAllCodes(argv[1]);
return 0;
}
RepShastri Ji is well known hindi and tamil vashikaran specialist. He will give you effective and simple totke to control ...
- rohitnandwate March 07, 2014