乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      假設(shè)客車的座位數(shù)是9行4列,使用二維數(shù)組在控制臺(tái)應(yīng)用程序中實(shí)現(xiàn)簡(jiǎn)單的客車售票系統(tǒng)。

       小世界的野孩子 2021-04-10

      具體要求為:

      使用一個(gè)二維數(shù)組記錄客車售票系統(tǒng)中的所有座位號(hào),并在每個(gè)座位號(hào)上都顯示有票,然后用戶輸入一個(gè)坐標(biāo)位置,按Enter鍵,即可將該座位號(hào)顯示為已售。

      首先我定義的輸入格式為:1,2

      個(gè)人認(rèn)為主要知識(shí)點(diǎn)偽代碼如下

      1.字符串分割

      char[] separator = { ',' }; 

        splitstrings = str.Split(separator);

      2.字符串前后去空

      str.Trim()

      3.轉(zhuǎn)換類型,如果不是int類型則為false,可以處理異常情況。

      int columnNum = 0;
      bool isColumn = int.TryParse(column, out columnNum);

       

      先創(chuàng)建如下腳本,然后在Main函數(shù)中直接調(diào)用即可。

       1 public class TicketingSystem
       2     {
       3         int[,] seatCount = new int[9, 4];
       4 
       5         public void CheckTicketCount()
       6         {
       7             bool res = true;
       8             String[] splitstrings = { "row", "col"};
       9             char[] separator = { ',' };
      10             while (res)
      11             {
      12                 Console.WriteLine("請(qǐng)輸入座位號(hào):");
      13                 string str = Console.ReadLine();
      14                 splitstrings = str.Split(separator);
      15                 if (str.Trim() == "Quit")
      16                 {
      17                     res = false;
      18                     Console.WriteLine("結(jié)束購(gòu)票");
      19                     return;
      20                 }
      21 
      22                 if (splitstrings.Length < 2)
      23                 {
      24                     Console.WriteLine("輸入的格式不正確");
      25                     continue;
      26                 }
      27                 string row = splitstrings[0].Trim();
      28                 string column = splitstrings[1].Trim();
      29 
      30                 int rowNum = 0;
      31                 bool isRow = int.TryParse(row, out rowNum);
      32                 if (!isRow || rowNum >= seatCount.GetLength(0))
      33                 {
      34                     Console.WriteLine("輸入的行不正確");
      35                     continue;
      36                 }
      37 
      38                 int columnNum = 0;
      39                 bool isColumn = int.TryParse(column, out columnNum);
      40                 if (!isColumn || columnNum >= seatCount.GetLength(1))
      41                 {
      42                     Console.WriteLine("輸入的列不正確");
      43                     continue;
      44                 }
      45                 if (seatCount[rowNum, columnNum] == 1)
      46                 {
      47                     Console.WriteLine("該座位已經(jīng)被購(gòu)買!");
      48                     continue;
      49                 }
      50                 seatCount[rowNum, columnNum] = 1;
      51                 Console.WriteLine(rowNum + "" + columnNum + "列車票售出");
      52                 bool isEmptySeat = false;
      53                 for (int i = 0; i < seatCount.GetLength(0); i++)
      54                 {
      55                     for (int j = 0; j < seatCount.GetLength(1); j++)
      56                     {
      57                         if (seatCount[i, j] == 0)
      58                         {
      59                             isEmptySeat = true;
      60                             break;
      61                         }
      62                     }
      63                     if (isEmptySeat)
      64                     {
      65                         break;
      66                     }
      67                 }
      68 
      69                 if (!isEmptySeat)
      70                 {
      71                     res = false;
      72                     Console.WriteLine("車票售完!");
      73                     return;
      74                 }
      75                 Console.WriteLine();
      76                 Console.WriteLine();
      77             }
      78         }
      79     }

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多