Skip to content

Count fibonacci numbers as number of string over alphabet

Ashish Sahu

Ashish Sahu

Asked Aug 7, 2015, 5:19 AM EDT1 answer
Share
LinkedInX
Hi Experts,
 
i am trying to make a program.
 
how to count string using Fibonacci numbers as numbers of strings over alphabets?
 
example: a=0,b=1 c=1,d=2,e=3,f=5,i=8..... like fibonacci series in alphabet order and end use put a string like : eidc
its sum count is 3+8+2+1=14


please help me.

Thanks & Regards
Ashish Sahu

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Ashish Sahu
    0
    C#
     class Fibonacci
        {
            static void Main(string[] args)
            {
                Dictionary<char, int> obj = new Dictionary<char, int>();
                int n = 26, f = 1, k = -1, s = 0;
                for (int i = 0; i < n; i++)
                {
                    s = k + f;
                    k = f;
                    f = s;
                    int num = 65 + i;
                    char c = (char)num; //Convert ASCII value into char
                    int a = char.ToUpper('b');// convert char into ASCII value
                    //Add values in to the dictionary
                    obj.Add(c, s);
                    //Console.WriteLine(s);
    
                }
                string str;
                str = Console.ReadLine().ToUpper();
                int sum = 0;
                for (int j = 0; j < str.Length; j++)
                {
                    sum = sum + obj[str[j]];
    
                }
                Console.WriteLine(sum);
                Console.ReadLine();
    
            }
        }
    0