using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace XuanJu
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("开始选举\n请输入有效候选人的代号(Judy-1,David-2,Mike-3)");
string[] sname = new string[] { "Judy", "David", "Mike" };
int[] vote = new int[] { 0, 0, 0 };
int h;
while (true)
{
h = int.Parse(Console.ReadLine());
switch (h)
{
case 0:
Console.Write("你输入有错误,本程序退出");
break;
case 1:
vote[0] = vote[0] + 1;
continue;
case 2:
vote[1] = vote[1] + 1;
continue;
case 3:
vote[2] = vote[2] + 1;
continue;
default:
Console.WriteLine("此票无效");
continue;
}
int Max = vote[0];
string S = sname[0];
for (int i = 1; i < sname.Length; i++)
{
if (Max < vote[i])
{
Max = vote[i];
S = sname[i]; }
}
Console.WriteLine("{0}{1}", S, Max); } }
}}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace XuanJu
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("开始选举\n请输入有效候选人的代号(Judy-1,David-2,Mike-3)");
string[] sname = new string[] { "Judy", "David", "Mike" };
int[] vote = new int[] { 0, 0, 0 };
int h;
while (true)
{
h = int.Parse(Console.ReadLine());
switch (h)
{
case 0:
Console.Write("你输入有错误,本程序退出");
break;
case 1:
vote[0] = vote[0] + 1;
continue;
case 2:
vote[1] = vote[1] + 1;
continue;
case 3:
vote[2] = vote[2] + 1;
continue;
default:
Console.WriteLine("此票无效");
continue;
}
int Max = vote[0];
string S = sname[0];
for (int i = 1; i < sname.Length; i++)
{
if (Max < vote[i])
{
Max = vote[i];
S = sname[i]; }
}
Console.WriteLine("{0}{1}", S, Max); } }
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货