返回列表 發帖
  1. using ConsoleApp1;
  2. using System;//程式庫呼叫
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq.Expressions;
  5. using ABC.qq;


  6. class Program//負責一部分工作的人
  7. {
  8.     static int[,] a = { { 1, 2, 3 }, { 4, 5, 6 } };
  9.     static int[,] b = new int[2, 3];
  10.     static void Main()
  11.     {

  12.         try
  13.         {
  14.             string[] str = Console.ReadLine().Split(' ');
  15.             if (str.Length != 6)
  16.                 throw new Exception();
  17.             for (int i = 0; i < str.Length; i++)
  18.             {
  19.                 if (Convert.ToInt32(str[i]) < 1 || Convert.ToInt32(str[i]) > 100)
  20.                     throw new Exception();
  21.                 else
  22.                 {
  23.                     b[i <= 2 ? 0 : 1, i > 2 ? i - 3 : i] = Convert.ToInt32(str[i]);
  24.                 }
  25.             }
  26.             int[,] c = compute();
  27.             print(c);

  28.         }
  29.         catch
  30.         {
  31.             Console.WriteLine("error");
  32.         }
  33.         Console.ReadKey();
  34.     }
  35.     static int[,] compute()
  36.     {
  37.         try
  38.         {
  39.             int[,] c = new int[2, 3];
  40.             for (int i = 0; i < 2; i++)
  41.             {
  42.                 for (int j = 0; j < 3; j++)
  43.                 {
  44.                     c[i, j] = a[i, j] + b[i, j];
  45.                 }
  46.             }
  47.             return c;

  48.         }
  49.         catch
  50.         {
  51.             return null;
  52.         }
  53.     }
  54.     static void print(int[,] c)
  55.     {
  56.         for (int i = 0; i < 2; i++)
  57.         {
  58.             for (int j = 0; j < 3; j++)
  59.             {
  60.                 Console.Write(c[i, j].ToString().PadLeft(4));//此字串會以空格填補左側至指定的總長度


  61.             }
  62.             Console.WriteLine();
  63.         }

  64.     }
  65. }
複製代碼
istak.teach2@gmail.com

TOP

返回列表