zoukankan      html  css  js  c++  java
  • 20150311

    练习题:

    一、 三个红球,五个白球,六个黑球,任取八个球且必须有一个白球,可能性有多少?             int a = 0;             for (int i = 0; i <= 3; i++)//红球             {                 for (int i1 = 0; i1 <= 5; i1++)//白球                 {                     for (int i2 = 0; i2 <= 6; i2++)//黑球                     {                         if (i + i1 + i2 == 8 && i > 0)                         {                             Console.WriteLine(i + "个白球;" + i1 + "个红球;" + i2 + "个黑球"); a++;                         }

                        }                 }             }             Console.WriteLine("可能性有" + a);

                Console.ReadLine();

    二、 小超市 100  95折 200  9折 300  85折 400以上  8折

    static void Main(string[] args)         {            Console.WriteLine("请输入一个值:");                         int n = Convert.ToInt32(Console.ReadLine());             dazhe(n);

            }                  static   public void  dazhe(int n)         {             string x="";             if (n<100)             {                 x = n.ToString ();             }             else if (n>=100&&n<200)             {                 x=n * 0.95+"元";             }             else if (n>=200&&n<300)             {                 x = n * 0.9 + "元";             }             else if (n>=300&&n<400)             {                 x = n * 0.85 + "元";             }             else if (n>=400)             {                 x = n * 0.80 + "元";             }             Console.Write(x);             Console.ReadLine();         }

    5、网吧充值 利用while循环一直执行 定义会员机构体 在循环外部定义一个集合用于存放会员结构体(用户名、密码、余额) 每次循环执行一次询问 (会员管理(新增会员、删除会员、余额查询(利用用户名查询)),充值管理(充值服务、扣费服务))

    会员2元一小时

    10元送2元, 20元送5元, 50元送20元, 100元送50元, 200元送150元。 300元以上充多少送多少 我冲多少钱 能玩多少小时 请提供具体信息。

    class Program     {         struct huiyuan         {             public string name;             public string password;             public double yue;         }         static void Main(string[] aaa)         {                        ArrayList Ul=new ArrayList();             while (true)             {

                    try                 {                 Console.WriteLine("请输入您要执行的操作:(1、会员管理 2、充值管理)");                int x=Convert.ToInt32( Console.ReadLine());                m(x, Ul);                 }                 catch (Exception)                 {                                                         }             }

            }         static void m(int x, ArrayList al)         {             switch (x)             {                 case 1:                     Console.WriteLine("1、添加会员 2、删除会员 3、余额查询");                     int xx =Convert.ToInt32( Console.ReadLine());                     huiyuanfuwu(xx, al);                     break;                 case 2:                     Console.WriteLine("1、充值服务 2、扣费服务");                     int xxx = Convert.ToInt32(Console.ReadLine());                     chongzhiguanli(xxx,al);                     break;                 default:                     break;             }         }

             static void chongzhiguanli(int x,ArrayList al)         {             switch (x)             {                 case 1:                     Console.Write("请输入要充值的用户名:");                     string sname = Console.ReadLine();                     foreach (huiyuan item in al)                     {                         if (item.name==sname)                         {                                                         Console.WriteLine("当前余额为:"+item.yue);                             Console.Write("请输入充值金额:");                             double m=Convert.ToInt32(Console.ReadLine());                             chongzhi(m,al,sname);                             break;

                            }                     }                     break;                 default:                     break;             }         }

             static void chongzhi(double m, ArrayList al,string sname)          {              double x = 0;//奖励金额             

                 if (m>=10&&m<20)              {                  x = 2;              }              else if (m >= 20 && m < 50)              {                  x = 5;              }              else if (m >= 50 && m < 100)              {                  x = 20;              }              else if (m >= 100 && m < 200)              {                  x = 50;              }              else if (m >= 200 && m < 300)              {                  x = 150;              }              else if (m >= 300)              {                  x = m;              }              else              {                  x = 0;              }              huiyuan temp=new huiyuan();              for (int i = 0; i < al.Count; i++)              {                  temp=((huiyuan)al[i]);                  if (temp.name==sname)                  {                                           temp.yue += Convert.ToDouble(m + x);                      Console.WriteLine("本次充值成功,充值金额为" + m + "。奖励金额为:" + x + ".充值后余额为:" + temp.yue);                      al.Insert(i, temp);                      al.RemoveAt(i + 1);                      break;                  }                               }                       }         static void huiyuanfuwu(int x, ArrayList al)         {             switch (x)             {                 case    1:                     huiyuan h = new huiyuan();                     Console.Write("请输入用户名:");                     h.name = Console.ReadLine();                     Console.Write("请输入密码:");                     h.password = Console.ReadLine();                     h.yue = 0;                     al.Add(h);                     break;                 case 2:                     Console.Write("请输入要删除的用户名:");                     string dname = Console.ReadLine();                     foreach (huiyuan item in al)                     {                         if (item.name==dname)                         {                             al.Remove(item);                             Console.WriteLine("删除成功!");                             break;                         }                     }

                        break;                 case 3:                     Console.Write("请输入要查询的用户名:");                     string sname = Console.ReadLine();                     foreach (huiyuan item in al)                     {                         if (item.name==sname)                         {                                                         Console.WriteLine("当前余额为:"+item.yue);                         }                     }                     break;                 default:                     break;             }         }

        } }

  • 相关阅读:
    .NET基础回顾(二)
    python 三元表达式、列表推导式、生成器表达式
    python 函数相关定义
    python 匿名函数
    python递归函数
    内置函数
    迭代器、生成器、面向过程编程
    python 函数对象、函数嵌套、名称空间与作用域、装饰器
    python django ORM 性能优化 select_related & prefetch_related
    python 函数
  • 原文地址:https://www.cnblogs.com/m123/p/4333045.html
Copyright © 2011-2022 走看看