Advertisement
ss3434

Untitled

Mar 19th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2.Message_Translator
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int number = int.Parse(Console.ReadLine());
  12. string comandSub = "";
  13. for (int i = 0; i < number; i++)
  14. {
  15. bool comandore = true;//tuka gi lsagame za da se nulirat vseki pat
  16. bool dec = true;
  17. string text = Console.ReadLine();
  18.  
  19. var numbers = new List<int>();//tuka pravime lista za da se nulira vseki pat
  20. if (text.Contains("!") && (text.Contains("[")) && text.Contains("]")&& text.Contains(":"))//proverka dali safarja
  21. {
  22.  
  23. string[] splitedInput = text.Split(":").ToArray();
  24. string comand = splitedInput[0];
  25. //proverka za []!
  26. if (comand[0] == '!' && comand[comand.Length - 1] == '!')//ako parviq i poslediq 4arsa !
  27. {
  28.  
  29. comandSub = comand.Substring(1, comand.Length - 2);//vzimame stringa ot parvi do opredelena daljina do pred posledniq
  30. if (comandSub.Length >= 3)
  31. {
  32.  
  33. if (char.IsLower(comandSub[0]))//dali parviq char e glavna bukva
  34. {
  35. comandore = false;
  36.  
  37. }
  38. for (int j = 1; j < comandSub.Length; j++)
  39. {
  40. if (char.IsUpper(comandSub[j]))
  41. {
  42. comandore = false;
  43. break;
  44. }
  45.  
  46. }
  47. }
  48. else
  49. {
  50. comandore = false;
  51. }
  52. }
  53. else
  54. {
  55. comandore = false;
  56. }
  57. string decript = splitedInput[1];
  58. if (decript[0] == '[' && decript[decript.Length - 1] == ']')
  59. {
  60. string decriptSub = decript.Substring(1, decript.Length - 2);
  61.  
  62.  
  63. if (decriptSub.Length >= 8)
  64. {
  65. for (int k = 0; k < decriptSub.Length; k++)
  66. {
  67. if (char.IsLetter(decriptSub[k]))//preverqvame teksta dali e ot bukvi
  68. {
  69. int curentnum = decriptSub[k];
  70. numbers.Add(curentnum);//ako e ot bukvi ima vzimame stoinosti
  71.  
  72. }
  73. else
  74. {
  75. dec = false;
  76. break;
  77. }
  78.  
  79. }
  80. }
  81. else
  82. {
  83. dec = false;
  84. }
  85. }
  86. else
  87. {
  88. dec = false;
  89. }
  90.  
  91.  
  92. }
  93. else
  94. {
  95. comandore = false;
  96. }
  97. if (comandore && dec)
  98. {
  99. Console.WriteLine($"{comandSub}: {string.Join(" ", numbers)} ");
  100. }
  101. else
  102. {
  103. Console.WriteLine($"The message is invalid");
  104. }
  105. }
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement