Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.69 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. namespace ForDZ
  8. {
  9. class Input
  10. {
  11. private IEnumerator<string> istream;
  12.  
  13. private static IEnumerable<string> GetNullStream()
  14. {
  15. while (true) yield return null;
  16. }
  17.  
  18. private static IEnumerator<string> GetIStream()
  19. {
  20. while (true)
  21. {
  22. IEnumerable<string> sstream;
  23. try
  24. {
  25. sstream = Console.ReadLine().Split().Where(s => s.Length > 0);
  26. }
  27. catch (Exception)
  28. {
  29. sstream = GetNullStream();
  30. }
  31.  
  32. foreach (string s in sstream)
  33. yield return s;
  34. }
  35. }
  36.  
  37. public Input()
  38. {
  39. istream = GetIStream();
  40. }
  41.  
  42. public string GetString()
  43. {
  44. istream.MoveNext();
  45. return istream.Current;
  46. }
  47.  
  48. public int GetInt()
  49. {
  50. return int.Parse(GetString());
  51. }
  52. }
  53.  
  54. class pr_7_VI_14
  55. {
  56. static Input reader;
  57.  
  58. public static void Task(Input input)
  59. {
  60. reader = input;
  61.  
  62. int n = reader.GetInt();
  63.  
  64. int[,] a = new int[n, n];
  65.  
  66. for (int y = 0; y < n; y++)
  67. {
  68. for (int x = 0; x < n; x++)
  69. {
  70. a[x, y] = input.GetInt();
  71. }
  72. }
  73.  
  74. int[] x_delete = new int[n];
  75. int[] y_delete = new int[n];
  76.  
  77. for (int x = 0; x < n; x++)
  78. {
  79. for (int y = 0; y < n; y++)
  80. {
  81. for (int i = 0; i < n; i++)
  82. {
  83. if (a[x, i] != a[i, y]) goto next_iter;
  84. }
  85.  
  86. x_delete[x] = -1;
  87. y_delete[y] = -1;
  88.  
  89. next_iter:;
  90. }
  91. }
  92.  
  93. /* // for debug
  94. Console.Write("\n ");
  95. for (int i = 0; i < n; i++)
  96. {
  97. Console.Write($"{(-x_delete[i])} ");
  98. }
  99. Console.WriteLine();
  100. for (int i = 0; i < n; i++)
  101. {
  102. Console.WriteLine($"{(-y_delete[i])} ");
  103. }
  104.  
  105. Console.Write("\n");
  106. */
  107.  
  108. int x_del_cnt = x_delete[0];
  109. int y_del_cnt = y_delete[0];
  110.  
  111. int[] x_offset = new int[n];
  112. int[] y_offset = new int[n];
  113.  
  114. for (int i = 1; i < n; i++)
  115. {
  116. x_offset[i] = x_del_cnt;
  117. y_offset[i] = y_del_cnt;
  118.  
  119. x_del_cnt += x_delete[i];
  120. y_del_cnt += y_delete[i];
  121. }
  122.  
  123. /* // for debug
  124. Console.Write("\n ");
  125. for (int i = 0; i < n; i++)
  126. {
  127. Console.Write($"{(-x_offset[i])} ");
  128. }
  129. Console.WriteLine();
  130. for (int i = 0; i < n; i++)
  131. {
  132. Console.WriteLine($"{(-y_offset[i])} ");
  133. }
  134. Console.Write("\n");
  135.  
  136. for (int y = 0; y < n; y++)
  137. {
  138. for (int x = 0; x < n; x++)
  139. {
  140. Console.Write($"({-x_offset[x]},{-y_offset[y]}) ");
  141. }
  142. Console.Write("\n");
  143. }
  144. Console.Write("\n");
  145. */
  146.  
  147. int width = n + x_del_cnt;
  148. int height = n + y_del_cnt;
  149.  
  150. for (int x = 0; x < n; x++)
  151. {
  152. for (int y = 0; y < n; y++)
  153. {
  154. a[x + x_offset[x], y + y_offset[y]] = a[x, y];
  155.  
  156. if(x >= width || y >= height)
  157. {
  158. a[x, y] = 0;
  159. }
  160. }
  161. }
  162.  
  163. Console.WriteLine();
  164.  
  165. for (int y = 0; y < n; y++)
  166. {
  167. for (int x = 0; x < n; x++)
  168. {
  169. Console.Write($"{a[x, y]} ");
  170. }
  171. Console.WriteLine();
  172. }
  173. }
  174. }
  175.  
  176. class pr_13_7
  177. {
  178. public static void Task()
  179. {
  180. string input = "ds :) :( :] sd:[ :-( :-) :-[df :-] " +
  181. ":---( :---] ::::---))) ;;;--[[[ ;;() ::[[]]";
  182. //Console.ReadLine();
  183.  
  184. string smile_expression = @"[:;]" + @"-*" + @"(\(+|\)+|\[+|\]+)";
  185.  
  186. MatchCollection res = Regex.Matches(input, smile_expression);
  187.  
  188. Console.WriteLine(res.Count);
  189. foreach(Match s in res) Console.WriteLine(s.Value);
  190. }
  191. }
  192.  
  193. class pr_13_9
  194. {
  195. public static void Task()
  196. {
  197. string[] input = {
  198. "Hello, I am a string.",
  199. "HaLlO AhaHahahhaha))0)",
  200. "This program is free-software; you can copy it.",
  201. "This program is free-software; you can copy it.",
  202. "This program is Free-software; you can copy it.",
  203. "THIS.",
  204. "In his house at Rl-yeh dead Cthulhu waits dreaming!",
  205. "Ph-nglui mglw-mafh Cthulhu R-lyeh wgah-nagl fhtagn.",
  206. "In Rl-yeh!",
  207. "Rl-yeh.",
  208. "free-software.",
  209. "Free-software.",
  210. "In!",
  211. "hello!",
  212. "Hello!",
  213. "HELLO!",
  214. "in!",
  215. "iN!",
  216. "In!",
  217. "IN!",
  218. "in.",
  219. "iN.",
  220. "In.",
  221. "IN.",
  222. "in...",
  223. "iN...",
  224. "In...",
  225. "IN...",
  226. "Hello...",
  227. "HeLlo!",
  228. "heLLo!",
  229. "HeLlo?",
  230. "Hello?",
  231. "Is this string work?",
  232. };
  233. //string input = Console.ReadLine();
  234.  
  235. string abbreviation = "([A-Z]+)";
  236. string word_first_part_big = "(([A-Z])([a-z]*))";
  237. string word_first_part_low = "([a-z]+)"; ;
  238. string word_first_part = "("+ word_first_part_big + "|" + word_first_part_low + ")";
  239. string word_second_part = "((-([a-z]+))?)";
  240. string lower_word = "("+ word_first_part + word_second_part + ")";
  241. string word = "(" + abbreviation + "|"+ lower_word + ")";
  242. string separators = @"(( - )|( )|(, )|(; )|(, - ))";
  243. string final = @"(" + "(...)" + "|" + @"[(\?)!.]" + ")";
  244. string sentence = word + "(" + separators + word + ")*" + final;
  245.  
  246. string expression = "^((" + sentence + ")+)$";
  247. Regex regex = new Regex(expression);
  248.  
  249. foreach (string s in input)
  250. {
  251. string t = regex.Match(s).Value;
  252. //Console.WriteLine($"> {s} ({s.Length}) -> {t} ({t.Length}) : {s.Length == t.Length}");
  253. Console.WriteLine($"> {s} -> {(s.Length == t.Length ? "YES" : "NO")}");
  254. }
  255. }
  256. }
  257.  
  258. class Program
  259. {
  260. static void Main(string[] args)
  261. {
  262. Console.WindowHeight += 10;
  263. Console.WindowWidth += 10;
  264. Input reader = new Input();
  265.  
  266. //pr_7_VI_14.Task(reader);
  267. //pr_13_7.Task();
  268. pr_13_9.Task();
  269.  
  270. Console.WriteLine("\n\nend.");
  271. Console.ReadKey();
  272. }
  273. }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement