返回列表 發帖

C# 7 307 反轉陣列

TQC+ 物件導向程式語言
最新一次更新時間:2024-01-05 14:52:39

1. 題目說明:
請新增一個主控台應用程式,加入C:\ANS.CSF\CS03資料夾中的CSD03.cs進行編寫。依下列題意進行作答:建立一個陣列,予以反轉後輸出,使輸出值符合題意要求。檔案名稱請另存新檔為CSA03.cs,儲存於C:\ANS.CSF\CS03資料夾,再進行評分。

2. 設計說明:
專案中已提供一個名為compute()的方法,接收Main()傳遞的一個陣列。請在Main()中宣告一個陣列,讓使用者輸入資料,直到輸入999結束,將輸入的資料存入此宣告的陣列,再將此陣列傳遞給compute()方法。
在compute()方法中進行陣列反轉,輸出陣列反轉前反轉後的內容。

3. 輸入輸出:
輸入說明
資料內容,直到輸入999結束

輸出說明
反轉前before、反轉後after的陣列內容

範例輸入1
901
293
John
999
範例輸出1
before:901 293 John
after:John 293 901

4. 評分項目:
(1) 符合設計說明輸出正確格式 配分        20
May

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;

  6. namespace CSA03
  7. {
  8.     class CSA03
  9.     {

  10.         static void Main(string[] args)
  11.         {
  12.             try
  13.             {
  14.                 List<string> lst = new List<string>();
  15.                 string str = "";
  16.                 while (true)
  17.                 {
  18.                     str = Console.ReadLine();
  19.                         if (str != "999")
  20.                         {
  21.                             lst.Add(str);
  22.                     }
  23.                     else
  24.                     {
  25.                         break;
  26.                     }
  27.                 }
  28.                 compute(lst);
  29.             }
  30.             catch
  31.             {
  32.                 Console.Write("error");
  33.             }
  34.             Console.ReadKey();
  35.         }
  36.         // ==================================================
  37.         // Please write your code in the specified Method
  38.         // Do NOT change the method name, type of parameter
  39.         // ==================================================
  40.         static void compute(List<string> lst)
  41.         {
  42.             Console.WriteLine("before:" + String.Join(" ", lst));
  43.             lst.Reverse();
  44.             Console.WriteLine("after:" + String.Join(" ", lst));
  45.         }
  46.   
  47.     }
  48. }
複製代碼
May

TOP

  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 void Main()
  9.     {
  10.         try
  11.         {


  12.             List<string> lst = new List<string>();
  13.             string str = "";
  14.             while (true)
  15.             {
  16.                 str = Console.ReadLine();
  17.                 if (str != "999")
  18.                 {
  19.                     lst.Add(str);
  20.                 }
  21.                 else
  22.                 {
  23.                     break;
  24.                 }
  25.             
  26.             }
  27.             compute(lst);
  28.         } catch
  29.         {
  30.             Console.WriteLine("error");
  31.         }
  32.         Console.ReadKey();

  33.    

  34.     }
  35.     static void compute(List<string> lst)
  36.     {
  37.         Console.WriteLine("before:"+String.Join(" ",lst));
  38.         lst.Reverse();
  39.         Console.WriteLine("afer:" + String.Join(" ", lst));
  40.     }

  41. }
複製代碼
istak.teach2@gmail.com

TOP

返回列表