要求写一个Candy类,使得该程序能按要求运行
using System;
using System.Collections.Generic;
using System.Text;
namespace Program
{
//哨声响起,一轮游戏开始,每个同学将手中糖果数的一半分给右边的同学
//开始的时候每个同学手中的糖果数为偶数
//每一轮游戏后,老师给糖果数为奇数的同学补1糖果
//当所有的同学手中的糖果一样时终止
//要求输出游戏进行的轮数和每个学生最终的糖果数
class Program
{
static void Main(string[] args)
{
int[][] data ={new int[] { 36, 2, 2, 2, 2, 2 }, new int[] { 2, 4, 6, 8 }};
int[,] result = new int[data.Length, 2];
Candy c = new Candy();
c.calcu(data, result);
for (int i = 0; i < data.Length; i++)
{
Console.WriteLine("经过{0}轮,每个人手中都有了{1}颗糖果", result[i, 0], result[i, 1]);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Program
{
//哨声响起,一轮游戏开始,每个同学将手中糖果数的一半分给右边的同学
//开始的时候每个同学手中的糖果数为偶数
//每一轮游戏后,老师给糖果数为奇数的同学补1糖果
//当所有的同学手中的糖果一样时终止
//要求输出游戏进行的轮数和每个学生最终的糖果数
class Program
{
static void Main(string[] args)
{
int[][] data ={new int[] { 36, 2, 2, 2, 2, 2 }, new int[] { 2, 4, 6, 8 }};
int[,] result = new int[data.Length, 2];
Candy c = new Candy();
c.calcu(data, result);
for (int i = 0; i < data.Length; i++)
{
Console.WriteLine("经过{0}轮,每个人手中都有了{1}颗糖果", result[i, 0], result[i, 1]);
}
Console.ReadLine();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货