Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ForDZ
- {
- class Input
- {
- private IEnumerator<string> istream;
- private static IEnumerable<string> GetNullStream()
- {
- while (true) yield return null;
- }
- private static IEnumerator<string> GetIStream()
- {
- while (true)
- {
- IEnumerable<string> sstream;
- try
- {
- sstream = Console.ReadLine().Split().Where(s => s.Length > 0);
- }
- catch (Exception)
- {
- sstream = GetNullStream();
- }
- foreach (string s in sstream)
- yield return s;
- }
- }
- public Input()
- {
- istream = GetIStream();
- }
- public string GetString()
- {
- istream.MoveNext();
- return istream.Current;
- }
- public int GetInt()
- {
- return int.Parse(GetString());
- }
- }
- class pr_7_VI_14
- {
- static Input reader;
- public static void Task(Input input)
- {
- reader = input;
- int n = reader.GetInt();
- int[,] a = new int[n, n];
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- a[x, y] = input.GetInt();
- }
- }
- int[] x_delete = new int[n];
- int[] y_delete = new int[n];
- for (int x = 0; x < n; x++)
- {
- for (int y = 0; y < n; y++)
- {
- for (int i = 0; i < n; i++)
- {
- if (a[x, i] != a[i, y]) goto next_iter;
- }
- x_delete[x] = -1;
- y_delete[y] = -1;
- next_iter:;
- }
- }
- /* // for debug
- Console.Write("\n ");
- for (int i = 0; i < n; i++)
- {
- Console.Write($"{(-x_delete[i])} ");
- }
- Console.WriteLine();
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine($"{(-y_delete[i])} ");
- }
- Console.Write("\n");
- */
- int x_del_cnt = x_delete[0];
- int y_del_cnt = y_delete[0];
- int[] x_offset = new int[n];
- int[] y_offset = new int[n];
- for (int i = 1; i < n; i++)
- {
- x_offset[i] = x_del_cnt;
- y_offset[i] = y_del_cnt;
- x_del_cnt += x_delete[i];
- y_del_cnt += y_delete[i];
- }
- /* // for debug
- Console.Write("\n ");
- for (int i = 0; i < n; i++)
- {
- Console.Write($"{(-x_offset[i])} ");
- }
- Console.WriteLine();
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine($"{(-y_offset[i])} ");
- }
- Console.Write("\n");
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- Console.Write($"({-x_offset[x]},{-y_offset[y]}) ");
- }
- Console.Write("\n");
- }
- Console.Write("\n");
- */
- int width = n + x_del_cnt;
- int height = n + y_del_cnt;
- for (int x = 0; x < n; x++)
- {
- for (int y = 0; y < n; y++)
- {
- a[x + x_offset[x], y + y_offset[y]] = a[x, y];
- if(x >= width || y >= height)
- {
- a[x, y] = 0;
- }
- }
- }
- Console.WriteLine();
- for (int y = 0; y < n; y++)
- {
- for (int x = 0; x < n; x++)
- {
- Console.Write($"{a[x, y]} ");
- }
- Console.WriteLine();
- }
- }
- }
- class pr_13_7
- {
- public static void Task()
- {
- string input = "ds :) :( :] sd:[ :-( :-) :-[df :-] " +
- ":---( :---] ::::---))) ;;;--[[[ ;;() ::[[]]";
- //Console.ReadLine();
- string smile_expression = @"[:;]" + @"-*" + @"(\(+|\)+|\[+|\]+)";
- MatchCollection res = Regex.Matches(input, smile_expression);
- Console.WriteLine(res.Count);
- foreach(Match s in res) Console.WriteLine(s.Value);
- }
- }
- class pr_13_9
- {
- public static void Task()
- {
- string[] input = {
- "Hello, I am a string.",
- "HaLlO AhaHahahhaha))0)",
- "This program is free-software; you can copy it.",
- "This program is free-software; you can copy it.",
- "This program is Free-software; you can copy it.",
- "THIS.",
- "In his house at Rl-yeh dead Cthulhu waits dreaming!",
- "Ph-nglui mglw-mafh Cthulhu R-lyeh wgah-nagl fhtagn.",
- "In Rl-yeh!",
- "Rl-yeh.",
- "free-software.",
- "Free-software.",
- "In!",
- "hello!",
- "Hello!",
- "HELLO!",
- "in!",
- "iN!",
- "In!",
- "IN!",
- "in.",
- "iN.",
- "In.",
- "IN.",
- "in...",
- "iN...",
- "In...",
- "IN...",
- "Hello...",
- "HeLlo!",
- "heLLo!",
- "HeLlo?",
- "Hello?",
- "Is this string work?",
- };
- //string input = Console.ReadLine();
- string abbreviation = "([A-Z]+)";
- string word_first_part_big = "(([A-Z])([a-z]*))";
- string word_first_part_low = "([a-z]+)"; ;
- string word_first_part = "("+ word_first_part_big + "|" + word_first_part_low + ")";
- string word_second_part = "((-([a-z]+))?)";
- string lower_word = "("+ word_first_part + word_second_part + ")";
- string word = "(" + abbreviation + "|"+ lower_word + ")";
- string separators = @"(( - )|( )|(, )|(; )|(, - ))";
- string final = @"(" + "(...)" + "|" + @"[(\?)!.]" + ")";
- string sentence = word + "(" + separators + word + ")*" + final;
- string expression = "^((" + sentence + ")+)$";
- Regex regex = new Regex(expression);
- foreach (string s in input)
- {
- string t = regex.Match(s).Value;
- //Console.WriteLine($"> {s} ({s.Length}) -> {t} ({t.Length}) : {s.Length == t.Length}");
- Console.WriteLine($"> {s} -> {(s.Length == t.Length ? "YES" : "NO")}");
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WindowHeight += 10;
- Console.WindowWidth += 10;
- Input reader = new Input();
- //pr_7_VI_14.Task(reader);
- //pr_13_7.Task();
- pr_13_9.Task();
- Console.WriteLine("\n\nend.");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement