Advertisement
knoteva

Untitled

Sep 12th, 2019
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _5._Seats
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int numOfTickets = int.Parse(Console.ReadLine());
  10.  
  11.             for (int i = 1; i <= numOfTickets; i++)
  12.             {
  13.                 string ticket = Console.ReadLine();
  14.                 //int ticketToNum = int.Parse(ticket.ToString());
  15.  
  16.                 char firstDigit = ticket[0];
  17.                 char secondDigit = ticket[1];
  18.                 char thirdDigit = ticket[2];
  19.                 char fourthDigit = ticket[3];
  20.  
  21.                 bool condition = firstDigit >= 'A' && firstDigit <= 'Z';
  22.  
  23.                 if (ticket.Length == 4) // Проверяваме дължината на съответния билет
  24.                 {
  25.                     if (condition)
  26.                     {
  27.                         Console.WriteLine($"Seat decoded: {firstDigit}{secondDigit}{thirdDigit}");
  28.                     }
  29.  
  30.                     else
  31.                     {
  32.                         Console.WriteLine($"Seat decoded: {fourthDigit}{secondDigit}{thirdDigit}");
  33.                     }
  34.                 }
  35.  
  36.                 else if (ticket.Length == 5 || ticket.Length == 6) // Проверяваме дължината на съответния билет
  37.                 {
  38.                     //char digit = char.Parse(secondDigit.ToString());
  39.                     var ASCIIDigit = (int)secondDigit; // взимаме ASCII стойността на втория символ
  40.                     Console.WriteLine($"Seat decoded: {firstDigit}{ASCIIDigit}");
  41.                 }
  42.  
  43.  
  44.             }
  45.  
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement