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 + "瓶盖";
    
            }
    

      

  • 相关阅读:
    菜鸡的Java笔记 第二十八
    菜鸡的Java笔记 第二十七
    菜鸡的Java笔记 第二十六
    菜鸡的Java笔记 第二十五 wrapperClass 包装类
    bzoj3238 [Ahoi2013]差异
    bzoj4516 [Sdoi2016]生成魔咒
    bzoj3998 [TJOI2015]弦论
    bzoj1965 [Ahoi2005]洗牌
    bzoj4896 [Thu Summer Camp2016]补退选
    bzoj5055 膜法师
  • 原文地址:https://www.cnblogs.com/Zingu/p/13953496.html
Copyright © 2011-2022 走看看