.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++;
                        }

                        
                    }
                }
                
            }
        }
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yours风之恋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值