zoukankan      html  css  js  c++  java
  • C# 循环的应用 手机号抽奖 选班长的练习题

    //第一题

    //20个手机号滚动显示随机抽出一个中奖号码来;

    static void bbb(string[] args)      

       {      

           string[] cellPhone = new string[] { "13012345678", "13109876543", "13287654678", "13309876789",

                     "13509878902", "13698374651", "13757893421", "13876561234",13909876543",

                    ""15034567438", "15111234795", "15894574839", "18210394857", "18302938475" };

                Random rand = new Random();    

             for(int i=0;i<50;i++)    

             {                 

               System.Threading.Thread.Sleep(100);                 //变慢一些。        

      int sub = rand.Next(cellPhone.Length);             //随机生成数组的下标。        

           string s = cellPhone[sub];                //根据下标取数组的元素值。  

                 Console.Clear();            //清屏

           Console.WriteLine(s);                //显示    

    }      

       }   

      }

    //30人投票,从5个候选人选一个出来。     

            int[] vote = new int[5];        

         for(int i=0;i<30;i++)        

         {               

      Console.Write("请第"+(i+1)+"位同学投票(0-4):");        

             int temp = Convert.ToInt32(Console.ReadLine());          

           if(temp <0 || temp >4)             

        {                 

        Console.WriteLine("废票");                 

        continue;                

    }             

        else        

             {       

                  vote[temp]++;         

            }           

      }

                //计算最终得票。             int max = 0, maxSub = 0;         

        for(int i=0;i<vote.Length;i++)       

          {            

         //把每位候选人的票数显示出来。                 Console.WriteLine("第" + (i + 1) + "号候选人的票数是:" + vote[i]);     

                //计算最大值。                 if(vote[i] > max)             

        {                     max = vote[i];             

            maxSub = i;          

           }       

          }

                //显示最终结果。             Console.WriteLine("最终投票结果为:"+(maxSub+1)+"号候选人当选,当选票数是"+max+"票。");   

          }   

      }

    }

  • 相关阅读:
    Codeforces Gym101502 K.Malek and Summer Semester
    Codeforces Gym101502 J-取数博弈
    Codeforces Gym101502 I.Move Between Numbers-最短路(Dijkstra优先队列版和数组版)
    Codeforces Gym101502 H.Eyad and Math-换底公式
    Codeforces Gym101502 F.Building Numbers-前缀和
    Codeforces Gym101502 B.Linear Algebra Test-STL(map)
    Codeforces Gym101502 A.Very Hard Question
    bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块
    Codeforces Round #250 (Div. 2) D. The Child and Zoo 并查集
    Codeforces Round #250 (Div. 2) A, B, C
  • 原文地址:https://www.cnblogs.com/981971554nb/p/4188101.html
Copyright © 2011-2022 走看看