.net(简单的解密小程序和小鸡问题的求解)

1,解密问题

/*
 * 破解密码:tbizljbqlfcivqbh
 *         已知加密方式
 * 
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestDecoding
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1,得到密文字符串
            string coding = "tbizljbqlfcivqbh";

            // 2,将密文转为字符数组
            char[] codingCharArray = coding.ToCharArray();

            // 3,破解密文
            for (int i = 1; i <= 25; i++)
            {
                Console.WriteLine("第{0}种可能明文",i);

                for (int j = 0; j < codingCharArray.Length; j++)
                {
                    if (codingCharArray[j] + (char)i > 'z')
                    {
                        codingCharArray[j] = (char)(codingCharArray[j] + (char)(i - 26));
                    }
                    else
                    {
                        codingCharArray[j] += (char)i;
                    }
                }

                foreach (char c in codingCharArray)
                {
                    Console.Write(c);
                }

                Console.WriteLine();
            }
        }
    }
}


2,小鸡问题:已知要用100元买100只鸡,公鸡5元1只,母鸡3元1只,小鸡1元3只,公鸡,母鸡,小鸡的个数不能为0.求各种购买方案。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestChecken
{
    class Program
    {
        static void Main(string[] args)
        {
            // 购买公鸡个数
            int maleChCount = 1;

            // 购买母鸡个数
            int famaleChCount = 1;

            // 购买小鸡个数
            int littleChCount = 1;

            // 统计方案个数
            int index = 1;
            // 用三重循环遍历求值
            for (maleChCount = 1; maleChCount < 100; maleChCount++)
            {
                for (famaleChCount = 1; famaleChCount < 100; famaleChCount++)
                {
                    for (littleChCount = 1; littleChCount < 100; littleChCount++)
                    {
                        if((100 == 5 * maleChCount + 3 * famaleChCount + littleChCount / 3)
                             && (100 == maleChCount + famaleChCount + littleChCount))
                        {
                            Console.WriteLine("方案" + index + " --------> " + "公鸡:" + maleChCount + ",   母鸡:" + famaleChCount
                                + "   ,小鸡:" + littleChCount);
                            index++;
                        }

                        
                    }
                }
                
            }
        }
    }
}


你可能感兴趣的:(.net)