class Program
{
static void Main(string[] args)
{
//寫一個模擬隨機大樂透搖號(5紅球+2籃球密似,自己百度了解)的程序菩貌,
//要求:直至其中一個紅球的個位數(shù)為8且兩個籃球的個位數(shù)都為2程序停止,并輸出最終顯示結果脑奠。
//每次要打印輸出:第i注:2,5,8纬凤,9捐寥,7*12笤昨,2
Console.WriteLine("------------------第一題------------------");
int[] arrRed = new int[5];//紅色球
int[] arrBlue = new int[2];//藍色球
int[] arr = new int[arrRed.Length + arrBlue.Length];//定義數(shù)組接收紅色數(shù)組和藍色數(shù)組的值
int count = 0;//計算下注的次數(shù)
int red8 = 0;//計算個位8出現(xiàn)的次數(shù)
int blue2 = 0;//計算個位出現(xiàn)2的次數(shù)
Random MyRan = new Random();//定義隨機
while (true)
{
count++;
//紅色球
AgainRed:
for (int i = 0; i < arrRed.Length; i++)
{
arrRed[i] = MyRan.Next(1, 36);//定義隨機數(shù)范圍
if (arrRed[i] % 10 == 8)//個位為8
{
red8++;//計算個位8出現(xiàn)的次數(shù)
}
//Console.Write(arrRed[i]);
}
//判斷紅色球隨機數(shù)是否重復;
for (int i = 0; i < arrRed.Length; i++)
{
for (int j = i + 1; j < arrRed.Length; j++)
{
if (arrRed[i] == arrRed[j])
{
red8 = 0;
goto AgainRed;
}
}
}
//藍色球
AgainBlue:
for (int j = 0; j < arrBlue.Length; j++)
{
arrBlue[j] = MyRan.Next(1, 13);//定義隨機數(shù)范圍
if (arrBlue[j] % 10 == 2)//個位為2
{
blue2++;// 計算個位2出現(xiàn)的次數(shù)
}
}
//判斷藍色球隨機數(shù)是否重復;
for (int i = 0; i < arrBlue.Length; i++)
{
for (int j = i + 1; j < arrBlue.Length; j++)
{
if (arrBlue[i] == arrBlue[j])
{
blue2 = 0;
goto AgainBlue;
}
}
}
//遍歷數(shù)組
for (int k = 0; k < arrRed.Length + arrBlue.Length; k++)
{
if (k == 0)
{
Console.Write("第{0}注 紅球*藍球: ", count);
}
if (k < arrRed.Length)
{
Console.Write(arrRed[k] + " ");
// arr[k] = arrRed[k];
}
else
{
if (k == arrRed.Length)
{
Console.Write("*");
}
Console.Write(" " + arrBlue[k - arrRed.Length]);
// arr[k] = arrBlue[k - arrRed.Length];
}
}
if (red8 == 1 && blue2 == 2)
{//判斷退出循環(huán)條件;
Console.WriteLine("\n\n\n\0\0\0\0\0\0\0\0恭喜您中獎了!!!\n買了{0}注,一共花了{1}元,終于中了2元!", count, count * 2);
break;
}
red8 = 0;//循環(huán)一次后歸零;
blue2 = 0;//循環(huán)一次后歸零;
Console.WriteLine();
}
//寫一個文字類提示游戲,輸入班里的每位同學名字回車后顯示他對應的組名握恳,以及組長瞒窒;
Console.WriteLine("\n\n------------------第二題------------------");
string[][] arrName = {
new string[]{"邊上海", "董應辰", "唐偉", "陸華強" },
new string[]{"黃程浩", "溫鵬飛", "黃仲發(fā)", "鄧華君", "聶偉進" },
new string[]{"孫海達","2", "高睿", "魯進雄", "黃雄", "林凱" },
new string[]{"孫輝成", "萬星作", "彭晉", "王林聰" },
new string[]{"1", "沈斌", "李昀熹", "梁廣超", "羅帥" },
new string[]{"徐平", "成俊杰", "江濤", "陳海建 ", "萬宇" },
new string[]{"郭旺", "堯銘杰", "譚其坤", "王楠楠", "郭建濤" ,"何川"}
};
againClass://重復標簽
Console.Write("\n請輸入同學姓名:\0\0\0");
string ClassName = Console.ReadLine();
Random MyRan1 = new Random();
//string classSir = "何川";
int num1 = MyRan1.Next(1, 200);//定義一個發(fā)紅包的隨機數(shù)
//遍歷數(shù)組判斷
for (int i = 0; i < arrName.Length; i++)
{
//arrName[i]=new string[];//什么時候要new
for (int j = 0; j < arrName[i].Length; j++)
{
if (ClassName != arrName[i][j])//遍歷數(shù)組,不是本班同學,重新輸入:
{
Console.WriteLine("你輸入的不是本班級同學!請重新輸入!");
goto againClass;
}
if (ClassName == arrName[i][j] && ClassName != arrName[i][0])//判斷組員不是小組長
{
Console.WriteLine("你輸入的 {0} 同學所屬第 {1} 組,組長是: {2} ;要發(fā) {3} 元紅包給班長!\n", ClassName, i + 1, arrName[i][0], num1);
goto againClass;//游戲繼續(xù)
}
else if (ClassName == arrName[i][0])//判斷組長
{
Console.WriteLine("你輸入的{0}同學是第 {1} 組的組長,要發(fā) {2} 元紅包給班長!\n", ClassName, i + 1, num1 * 10000);
goto againClass;//游戲繼續(xù)
}
else if (ClassName == arrName[arrName.Length - 1][arrName[arrName.Length - 1].Length - 1])//最后一個下標是何sir,游戲結束!
{
Console.WriteLine("你輸入的是何Sir,何Sir給你們每個人發(fā) {0} 萬元!游戲結束!\n", num1);
goto ending;//游戲結束
}
//Console.WriteLine(arrName[i][j]+" ");
}
}
ending://結束標簽
Console.ReadKey();
}
}
Unity3D開發(fā)-C#語言進階篇(二維數(shù)組應用詳解)
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來礁遵,“玉大人轻绞,你說我怎么就攤上這事¢欢” “怎么了铲球?”我有些...
- 正文 為了忘掉前任然走,我火速辦了婚禮援制,結果婚禮上,老公的妹妹穿的比我還像新娘芍瑞。我一直安慰自己晨仑,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布拆檬。 她就那樣靜靜地躺著洪己,像睡著了一般。 火紅的嫁衣襯著肌膚如雪竟贯。 梳的紋絲不亂的頭發(fā)上答捕,一...
- 文/蒼蘭香墨 我猛地睜開眼蜘欲,長吁一口氣:“原來是場噩夢啊……” “哼益眉!你這毒婦竟也來了?” 一聲冷哼從身側響起芒填,我...
- 正文 年R本政府宣布,位于F島的核電站座泳,受9級特大地震影響惠昔,放射性物質發(fā)生泄漏幕与。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一镇防、第九天 我趴在偏房一處隱蔽的房頂上張望啦鸣。 院中可真熱鬧,春花似錦来氧、人聲如沸诫给。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽中狂。三九已至,卻和暖如春考传,著一層夾襖步出監(jiān)牢的瞬間吃型,已是汗流浹背证鸥。 一陣腳步聲響...