encho253

Untitled

Nov 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class SingingCats
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         ReadData();
  12.     }
  13.     public static void ReadData()
  14.     {
  15.         string catsString = Console.ReadLine();
  16.         int cats = Int32.Parse(Regex.Match(catsString, @"\d+").Value);
  17.  
  18.         string songsString = Console.ReadLine();
  19.         int songs = Int32.Parse(Regex.Match(songsString, @"\d+").Value);
  20.  
  21.         bool[] arraySongs = new bool[songs];
  22.         bool[] arrayCats = new bool[cats];
  23.         int[,] table = new int[2, songs];
  24.  
  25.         int catCounter = 0;
  26.         int songCounter = 0;
  27.         int minSongs = 0;
  28.  
  29.         StringBuilder builder = new StringBuilder();
  30.  
  31.         do
  32.         {
  33.             string text = Console.ReadLine();
  34.  
  35.             if (text != "Mew!")
  36.             {
  37.                 int catNumber = Int32.Parse(Regex.Match(text, @"\d+").Value);
  38.  
  39.                 char[] reverse = text.ToCharArray();
  40.                 Array.Reverse(reverse);
  41.                 text = new string(reverse);
  42.                 int songNumber = Int32.Parse(Regex.Match(text, @"\d+").Value);
  43.  
  44.                 if (arraySongs[songNumber - 1] == true && arrayCats[catNumber - 1] == false)
  45.                 {
  46.                     catCounter++;
  47.                     table[1, songNumber - 1] += catCounter;
  48.                     arrayCats[catNumber - 1] = true;                
  49.                 }
  50.                 else if (arraySongs[songNumber - 1] == false && arrayCats[catNumber - 1] == false)
  51.                 {
  52.                     catCounter++;
  53.                     songCounter++;
  54.                     minSongs++;
  55.                     arrayCats[catNumber - 1] = true;
  56.                     arraySongs[songNumber - 1] = true;
  57.                 }
  58.                 else if (arrayCats[catNumber - 1] == true)
  59.                 {
  60.                     minSongs--;
  61.                     if (arraySongs[songNumber - 1] == false)
  62.                     {
  63.                         songCounter++;
  64.                     }
  65.                 }
  66.                 else if (arraySongs[songNumber - 1] == true && arrayCats[catNumber - 1] == false)
  67.                 {
  68.                     catCounter++;
  69.                     arrayCats[catNumber - 1] = true;
  70.                 }
  71.                 if (table[1, songNumber - 1] == cats && songCounter == songs)
  72.                 {
  73.                     minSongs = 1;
  74.                 }
  75.             }
  76.             else
  77.             {
  78.                 break;
  79.             }
  80.         } while (true);
  81.  
  82.         Calculation(arraySongs, arrayCats, table,catCounter,songCounter,minSongs);
  83.     }
  84.     static void Calculation(bool[] arrSongs, bool[] arrCat, int[,] tabl,int catCounter,int songCounter,int minSongs)
  85.     {
  86.         List<int> numbers = new List<int>();
  87.  
  88.  
  89.         for (int i = 0; i < arrSongs.Length; i++)
  90.         {
  91.             if (arrSongs[i] != true)
  92.             {
  93.                 Console.WriteLine("No concert!");
  94.                 return;
  95.             }
  96.         }
  97.         for (int i = 0; i < arrCat.Length; i++)
  98.         {
  99.             if (arrCat[i] != true)
  100.             {
  101.                 Console.WriteLine("No concert!");
  102.                 return;
  103.             }
  104.         }
  105.         Console.WriteLine(minSongs);      
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment