zoukankan      html  css  js  c++  java
  • 10块钱可以喝几瓶?

    /*
     题目:
    啤酒2块钱1瓶,
    4个瓶盖换1瓶
    2个空瓶换1瓶
    
    问:10块钱可以喝几瓶?
     */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace  Serbia
    {
         
        class Beers
        {
            public int Count = 0;
            public int pg=0;
            public int pz=0;
            public int UnitPrice = 2;
            public Beers( )
            { 
            } 
            public Beers(int money)
            {
               Count= money / UnitPrice;
               pg = Count;
               pz = Count;  
            } 
    
            public Beers getMaxCount()
            {
                while (pg / 4 > 0 || pz / 2 > 0)
                {
                    if (pg / 4>0)
                    {
                        pg = pg - 4;
                        pg++;
                        pz++; 
                        Count++;
                    }
                    if (pz / 2>0)
                    {
                        pz = pz - 2;
                        pg++;
                        pz++;
                        Count++;
                    }
                }
                return this;
            }
        }
    }
    

      

     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                _Init();
            }
    
            private void _Init()
            {
                richTextBox1.Text= @"
                题目:  
                啤酒2块钱1瓶,
                4个瓶盖换1瓶
                2个空瓶换1瓶
                问:10块钱可以喝几瓶?";
                richTextBox1.ReadOnly = true; 
            }
            private Func<int, int, Beers> MCount = (my, credit) =>
            {
                Beers br = new Beers();
                int Count, pg, pz =0;
                Count = my / 2;
                pg=Count;
                pz = Count;
                while (pg / 4 > 0 || pz / 2 > 0)
                {
                    if (pg / 4 > 0)
                    {
                        pg = pg - 4;
                        pg++;
                        pz++;
                        Count++;
                    }
                    if (pz / 2 > 0)
                    {
                        pz = pz - 2;
                        pg++;
                        pz++;
                        Count++;
                    }
                }
                while ((pg+1) / 4 > 0 || (pz+1) / 2 > 0)
                {
                    pg++;
                    pz++;
                    Count++;
                    if (pg / 4 > 0)
                    {
                        pg = pg - 4;
                        pg++;
                        pz++;
                        Count++;
                    }
                    if (pz / 2 > 0)
                    {
                        pz = pz - 2;
                        pg++;
                        pz++;
                        Count++;
                    }
                    pg--;
                    pz--;
                    Count--;
                }
                br.pg = pg;
                br.pz = pz;
                br.Count = Count;
                return br;
            };
            private void button1_Click(object sender, EventArgs e)
            { 
                label2.Text = "";
                Beers be = new Beers(Convert.ToInt16(numericUpDown1.Value));
                //Beers be = MCount(Convert.ToInt16(numericUpDown1.Value),3);
                be = be.getMaxCount();
                int count = be.Count;
                int pz = be.pz;
                int pg = be.pg;
    
               label2.Text= "一共可以喝" + count + "瓶,剩下" + pz + "瓶子、剩下" + pg + "瓶盖";
    
            }
    

      

  • 相关阅读:
    Handler消息传递机制
    Calendar 类的应用
    English--分词短语
    English--定语从句
    English--状语从句
    English--名词从句
    English--并列句
    English--不完全及物动词与授予动词
    爬虫--selenium之 chromedriver与chrome版本映射表(最新至v2.46版本chromedriver)
    English--动词语态
  • 原文地址:https://www.cnblogs.com/Zingu/p/13953496.html
Copyright © 2011-2022 走看看