- 最後登錄
- 2024-4-26
- 在線時間
- 0 小時
- 註冊時間
- 2016-8-22
- 閱讀權限
- 20
- 精華
- 0
- UID
- 16624936
- 帖子
- 61
- 積分
- 49 點
- 潛水值
- 26820 米
| 若瀏覽伊莉的時侯發生問題或不正常情況,請使用Internet Explorer(I.E)。 第二題- //讀檔案內容到字串陣列
- //string[] arr1 = System.IO.File.ReadAllLines("input.txt");
- //此處用宣告字串代替
- string[] arr1 = new string[4] { "3 2", "43 21", "-28 90", "27 17" };
- //切割字串並轉成數字放進陣列
- int[,] arr2 = new int[4, 2];
- for (int i = 0; i < 4; i++)
- {
- string[] temp = arr1[i].Split(' ');
- arr2[i, 0] = Convert.ToInt32(temp[0]);
- arr2[i, 1] = Convert.ToInt32(temp[1]);
- }
- int maxI = 0, maxJ = 0;
- int minI = 0, minJ = 0;
- int max = arr2[0, 0], min = arr2[0, 0];
- for (int i = 0; i <= arr2.GetUpperBound(0); i++)
- {
- for (int j = 0; j <= arr2.GetUpperBound(1); j++)
- {
- if (arr2[i, j] > max)
- {
- maxI = i;
- maxJ = j;
- max = arr2[i, j];
- }
- else if (arr2[i, j] < min)
- {
- min = arr2[i, j];
- minI = i;
- minJ = j;
- }
- }
- }
- Console.WriteLine("max:{0}({1},{2})",max,maxI,maxJ);
- Console.WriteLine("min:{0}({1},{2})",min,minI,minJ);
複製代碼 第三題- Console.Write("請輸入一個正整數:");
- int money = Convert.ToInt32(Console.ReadLine());
- int count50 = 0;
- int count10 = 0;
- int count5 = 0;
- int count1 = 0;
- count50 = money / 50;
- count10 = (money - (count50 * 50)) / 10;
- count5 = (money - count50 * 50 - count10 * 10) / 5;
- count1 = money - count50 * 50 - count10 * 10 - count5 * 5;
- Console.WriteLine("{0} {1} {2} {3}", count50, count10, count5, count1);
複製代碼 第五題
先建一個方法- static double GetVolume(double l,double w, double h)
- {
- return w * h * l;
- }
複製代碼 呼叫方法- Console.Write("請輸入三個浮點數(以分號分隔):");
- string[] input = Console.ReadLine().Split(';');
- double temp;
- double[] inputD = input.Select(str => double.TryParse(str, out temp) ? temp : 0).ToArray();
- Console.WriteLine("長方體的長為" + inputD[0].ToString("0.000"));
- Console.WriteLine("長方體的寬為" + inputD[1].ToString("0.000"));
- Console.WriteLine("長方體的高為" + inputD[2].ToString("0.000"));
- Console.WriteLine("長方體的體積為" + GetVolume(inputD[0], inputD[1], inputD[2]).ToString("0.00"));
複製代碼 第八題- string input = "aeiou";
- Hashtable ht = new Hashtable();
- for (int i = 0; i < input.Length; i++)
- {
- if (ht.ContainsKey(input[i]))//已存在個數加1
- ht[input[i]] = Convert.ToInt32(ht[input[i]]) + 1;
- else
- ht.Add(input[i], 1);//增加新的key
- }
- foreach (char s in ht.Keys)
- {
- Console.WriteLine("{0}:{1}", s, ht[s]);
- }
複製代碼 第九題- //從檔案讀入資料
- //string[] Alines = System.IO.File.ReadAllLines("inputA.txt");
- //string[] Blines = System.IO.File.ReadAllLines("inputB.txt");
- //切割字串並轉成數字放進陣列
- //以下假設已將檔案內矩陣都轉進陣列(此處用宣告代替)
- int[,] A = new int[3, 3] { { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 } };
- int[,] B = new int[3, 3] { { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 } };
- int[,] C = new int[3, 3];//存相加結果
- int[,] D = new int[3, 3];//存相減結果
- int[,] E = new int[3, 3];//存相乘結果
-
- for (int row = 0; row <= E.GetUpperBound(0); row++)
- {
- for (int col = 0; col <= E.GetUpperBound(1); col++)
- {
- C[row, col] = A[row, col] + B[row, col];//相加
- D[row, col] = A[row, col] - B[row, col];//相減
- //相乘
- for (int inner = 0; inner <= B.GetUpperBound(0); inner++)
- {
- E[row, col] += A[row, inner] * B[inner, col];
- }
- }
- }
- //相加結果
- for (int i = 0; i <= C.GetUpperBound(0); i++)
- {
- for (int j = 0; j <= C.GetUpperBound(1); j++)
- {
- Console.Write("{0} ", C[i, j]);
- }
- Console.WriteLine();
- }
- //相減結果
- for (int i = 0; i <= D.GetUpperBound(0); i++)
- {
- for (int j = 0; j <= D.GetUpperBound(1); j++)
- {
- Console.Write("{0} ", D[i, j]);
- }
- Console.WriteLine();
- }
- //相乘結果
- for (int i = 0; i <= E.GetUpperBound(0); i++)
- {
- for (int j = 0; j <= E.GetUpperBound(1); j++)
- {
- Console.Write("{0} ", E[i, j]);
- }
- Console.WriteLine();
- }
複製代碼 ... |
|