- using ConsoleApp1;
- using System;//程式庫呼叫
- using System.ComponentModel.DataAnnotations;
- using System.Linq.Expressions;
- using ABC.qq;
- class Program//負責一部分工作的人
- {
- static int[,] a = { { 1, 2, 3 }, { 4, 5, 6 } };
- static int[,] b = new int[2, 3];
- static void Main()
- {
- try
- {
- string[] str = Console.ReadLine().Split(' ');
- if (str.Length != 6)
- throw new Exception();
- for (int i = 0; i < str.Length; i++)
- {
- if (Convert.ToInt32(str[i]) < 1 || Convert.ToInt32(str[i]) > 100)
- throw new Exception();
- else
- {
- b[i <= 2 ? 0 : 1, i > 2 ? i - 3 : i] = Convert.ToInt32(str[i]);
- }
- }
- int[,] c = compute();
- print(c);
- }
- catch
- {
- Console.WriteLine("error");
- }
- Console.ReadKey();
- }
- static int[,] compute()
- {
- try
- {
- int[,] c = new int[2, 3];
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- c[i, j] = a[i, j] + b[i, j];
- }
- }
- return c;
- }
- catch
- {
- return null;
- }
- }
- static void print(int[,] c)
- {
- for (int i = 0; i < 2; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- Console.Write(c[i, j].ToString().PadLeft(4));//此字串會以空格填補左側至指定的總長度
- }
- Console.WriteLine();
- }
- }
- }
複製代碼 |