Advertisement
Guest User

cc1

a guest
Apr 19th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. namespace CodeCup
  6. {
  7.     class Program
  8.     {
  9.         static bool Check(string[][] x)
  10.         {
  11.             var result = false;
  12.  
  13.             foreach (var i in x)
  14.             {
  15.                 foreach (var i2 in i)
  16.                 {
  17.                     if (i2 == "0")
  18.                         result = true;
  19.                 }
  20.             }
  21.  
  22.             int n = x.Length;
  23.  
  24.             for (int j = 0; j < n -1; j++ )
  25.                 for (int j2 = 0; j2 < n - 1; j2++)
  26.                 {
  27.                     if (
  28.                         x[j][j2] == x[j+1][j2]
  29.                         ||
  30.                         x[j][j2] == x[j ][j2 + 1]
  31.                        
  32.                        
  33.                         )
  34.                     {
  35.                         result = true;
  36.                     }
  37.                 }
  38.  
  39.  
  40.                 return result;
  41.         }
  42.  
  43.         static void Main(string[] args)
  44.         {
  45.             string filename;
  46.            
  47.             if (args.Length > 0 )
  48.                 filename = args[0];
  49.  
  50.             // закомментить
  51.             filename = "input.txt";
  52.             string outputFilename = filename + ".a";
  53.  
  54.             int t;
  55.             int n;
  56.             List<string> answers = new List<string>();
  57.  
  58.  
  59.             using (StreamReader reader = new StreamReader(filename))
  60.             {
  61.                 string line;
  62.  
  63.                 line = reader.ReadLine();
  64.                 t = int.Parse(line);
  65.  
  66.                 for (int i = 0; i < t; i++)
  67.                 {
  68.                    
  69.                     line = reader.ReadLine();
  70.                     n = int.Parse(line);
  71.                     string[][] x = new string [n][];
  72.  
  73.                     for (int i2 = 0; i2 < n; i2++)
  74.                     {
  75.                         line = reader.ReadLine();
  76.                         x[i2] = line.Split(new Char[] {' '});
  77.                         //Console.WriteLine(string.Join(",", x[i2]));
  78.                     }
  79.  
  80.                     answers.Add(Check(x) ? "YES" : "NO");
  81.                     //Console.WriteLine(Check(x) ? "YES" : "NO");
  82.                 }
  83.  
  84.  
  85.             }
  86.  
  87.             File.WriteAllLines(outputFilename, answers);
  88.  
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement