Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             StreamReader inpFile = new StreamReader("input.txt");
  11.             StreamWriter outpFile = new StreamWriter("output.txt");
  12.            
  13.             var nString = inpFile.ReadLine().Split(' ');
  14.             int n = int.Parse(nString[0]);
  15.             int m = int.Parse(nString[1]);
  16.             int[,] data = new int[m, n + 1];
  17.             bool[] nots = new bool[n];
  18.             bool[] t = new bool[n];
  19.             int[] s = new int[n];
  20.             int c = 0, q = 0, z = 0;
  21.  
  22.             for (int i = 0; i < m; i++) {
  23.                 var str = inpFile.ReadLine().Split(' ');
  24.                 for (int j = 0; j <= n; j++) {
  25.                     data[i, j] = int.Parse(str[j]);
  26.                 }
  27.  
  28.                 for (int j = 0; j < n; j++){
  29.                     if (data[i, j] == 1 && data[i, n] == 0 && !nots[j]) {
  30.                         nots[j] = true;
  31.                         c++;
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             for (int i = 0; i < m; i++) {
  37.                 var count = 0;
  38.  
  39.                 if (data[i, n] == 0)
  40.                     continue;
  41.                 for (int j = 0; j < n; j++) {
  42.                     if (data[i, j] == 1 && !nots[j]) {
  43.                         count++;
  44.                         q = j;
  45.                     }
  46.                 }
  47.  
  48.                 if (count == 0) {
  49.                     outpFile.Write("Incorrect");
  50.                     outpFile.Flush();
  51.                     return;
  52.                 }
  53.  
  54.                 if (count == 1 && !t[q]) {
  55.                     t[q] = true;
  56.                     z++;
  57.                 }
  58.             }
  59.  
  60.             outpFile.Write("{0} ", c);
  61.            
  62.             for (int i = 0; i < n; i++) {
  63.                 if (nots[i])
  64.                     outpFile.Write("{0} ", i + 1);
  65.             }
  66.             outpFile.WriteLine();
  67.  
  68.             outpFile.Write("{0} ", z);
  69.  
  70.             for (int i = 0; i < n; i++) {
  71.                 if (t[i])
  72.                     outpFile.Write("{0} ", i + 1);
  73.             }
  74.             outpFile.WriteLine();
  75.             outpFile.Write("{0} ", n - z - c);
  76.  
  77.             for (int i = 0; i < n; i++) {
  78.                 if (!nots[i] && !t[i])
  79.                     outpFile.Write("{0} ", i + 1);
  80.             }
  81.  
  82.             outpFile.Flush();
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement