Skip to content

Instantly share code, notes, and snippets.

@Aduciicba
Created May 21, 2016 19:14
Show Gist options
  • Save Aduciicba/89afa917d1ba853111fdae66e4d14549 to your computer and use it in GitHub Desktop.
Save Aduciicba/89afa917d1ba853111fdae66e4d14549 to your computer and use it in GitHub Desktop.
ya_ex1
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader("input.txt");
var wordsCount = Int32.Parse(file.ReadLine());
string[] lines = new string[wordsCount];
int i = 0;
while ((line = file.ReadLine()) != null)
{
lines[i] = line;
i++;
}
file.Close();
int length = lines[0].Length;
string result = "";
for(i = 0; i < length; i++ )
{
Dictionary<char, int> values = new Dictionary<char, int>();
for(int j = 0; j < wordsCount; j++)
{
if (values.ContainsKey(lines[j][i]))
values[lines[j][i]] += 1;
else
values.Add(lines[j][i], 1);
}
result += (from x in values where x.Value == values.Max(v => v.Value) select x.Key).First();
}
Console.WriteLine(result);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment