Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _3._Camera_View
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13. int skipM = nums[0];
  14. int takeN = nums[1];
  15.  
  16. string input = Console.ReadLine();
  17.  
  18. List<string> finalWords = new List<string>();
  19.  
  20. for (int i = 0; i < input.Length - 1; i++)
  21. {
  22. string takeWord = "";
  23. if (input[i] == '|' && input[i + 1] == '<')
  24. {
  25. for (int j = i + 1; j < i+skipM+takeN + 1; j++)
  26. {
  27. if (input[j] == '|' && input[j + 1] == '<')
  28. {
  29. break;
  30. }
  31. takeWord += input[j + 1];
  32. }
  33.  
  34. if(takeWord.Length < takeN)
  35. {
  36. takeN = takeWord.Length;
  37. takeWord = takeWord.Substring(skipM, takeN);
  38. }
  39. else
  40. {
  41. takeWord = takeWord.Substring(skipM, takeN);
  42. }
  43. }
  44.  
  45. if (takeWord.EndsWith('|'))
  46. {
  47. takeWord = takeWord.TrimEnd('|');
  48. }
  49. if(takeWord != "")
  50. {
  51. finalWords.Add(takeWord);
  52.  
  53. }
  54. }
  55.  
  56. Console.WriteLine(string.Join(", ", finalWords));
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement