zoukankan      html  css  js  c++  java
  • 编程实践57

    编程实践5-7

    课程元素类型 任务

    统计选票。100位村民投票,从3位候选人中选出村长和村支书。规定得票最高者为村长,次高者为村支书。统计时,输入得票候选人的姓氏,输出投票结果。

    总结:大于两个的数据,尽量用数组,写程序要考虑到拓展,要程序拥有良好的拓展性。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace sj5_7
    {
        class Program
        {
            static void Main(string[] args)
            {
                string strTem;
                string[] strB;
                int[] intA;
                int intTem;
    
                intA = new int[3];
                strB = new string[3];
    
                strB[0] = "Z";
                strB[1] = "L";
                strB[2] = "W";
    
                Console.WriteLine("请输入投票:");
                strTem = Console.ReadLine();
                string[] strA = strTem.Split(' ');
    
                for (int i = 0; i < strB.Length; i++)
                {
                    for (int j = 0; j < strA.Length; j++)
                    {
                        if (strB[i] == strA[j])
                        {
                            intA[i]++;
                        }
                    }
                    
                }
    
                for (int i = 0; i <intA.Length; i++)
                {
                    for (int j = i + 1; j < intA.Length; j++)
                    {
                        if (intA[i] < intA[j])
                        {
                            intTem = intA[i];
                            intA[i] = intA[j];
                            intA[j] = intTem;
    
                            strTem = strB[i];
                            strB[i] = strB[j];
                            strB[j] = strTem;
                        }
                    }
                }
    
                Console.WriteLine("村长是:{0},得票{1}",strB[0],intA[0]);
                Console.WriteLine("村支书是:{0},得票{1}", strB[1], intA[1]);
                Console.ReadKey(true);
            }
        }
    }
  • 相关阅读:
    Oracle面试题及答案整理
    Oracle问题总结
    Dubbo(四) -- telnet命令
    Dubbo(三) -- 多协议支持与多注册中心
    每天一算法 -- (冒泡排序)
    Dubbo(二) -- Simple Monitor
    数据库优化
    ActiveMQ内存配置和密码设置
    Dubbo源码导入Eclipse遇到的问题
    Dubbo(一) -- 初体验
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2792021.html
Copyright © 2011-2022 走看看