Friday, November 15, 2013

Reverse Alphabet Codes


Given the following information:

a = 26, b = 25, c = 24, d = 23 ..... x = 3, y = 2, z = 1

What is the sum of each letter of this sentence: "The quick brown fox jumped over the cow"? 

Note: A white space has no value

Language C++: 

#include<iostream>
using namespace std;

class rev_alph {
 
            private:
                   int sum;
                   string str;
            public:
                   rev_alph() { 
                           sum = 0;
                           str = "The quick brown fox jumped over the cow";
                   }
                   void reversealpha() { 
                           int i;
                           str[0] = tolower(str[0]);
                           int len = str.length();
                           for (i = 0 ; i < len ; i++) { 
                                     if (str[i] == ' ') {
                                               sum += 0;
                                      }
                                      else {
                                               sum += (26 - (str[i] - 'a'));
                                      }
                            }
                            cout<<sum<<endl;
   
                     }
};

int main() {
       rev_alph obj;
       obj.reversealpha();
       return(0);
}

Output:
450

By +Dixit Singla 

No comments: