Palindrome from the product of two 3-digit numbers

后端 未结 6 1660
北海茫月
北海茫月 2020-12-20 08:12

I want to find the largest palindrome that can be obtained through the multiplication of two 3-digit numbers.

I started off with a and b both being 999, and to decre

6条回答
  •  借酒劲吻你
    2020-12-20 08:40

    In C# - solution in gist - https://gist.github.com/4496303

    public class worker { public worker(){

        }
        public void start()
        {
            int MAX_NUMBER = 999;
            for (int Number = MAX_NUMBER; Number >= 0; Number--)
            {
                string SNumberLeft = Number.ToString();
                string SNumberRight = Reverse(Number.ToString());
                int palindromic = Convert.ToInt32(SNumberLeft + SNumberRight);
    
                for (int i = MAX_NUMBER; i >= 1; i--)
                {
                    for (int l = MAX_NUMBER; l >= 1; l--)
                    {
                        if ((i * l) - palindromic == 0)
                        {
                            System.Diagnostics.Debug.WriteLine("Result :" + palindromic);
                            return;
                        }
                    }
                }
    
               // System.Diagnostics.Debug.WriteLine( palindromic); 
            }           
    
        }
    
        public string Reverse(String s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }
    
    
    
    }
    

提交回复
热议问题