Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _2.Message_Translator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int number = int.Parse(Console.ReadLine());
- string comandSub = "";
- for (int i = 0; i < number; i++)
- {
- bool comandore = true;//tuka gi lsagame za da se nulirat vseki pat
- bool dec = true;
- string text = Console.ReadLine();
- var numbers = new List<int>();//tuka pravime lista za da se nulira vseki pat
- if (text.Contains("!") && (text.Contains("[")) && text.Contains("]")&& text.Contains(":"))//proverka dali safarja
- {
- string[] splitedInput = text.Split(":").ToArray();
- string comand = splitedInput[0];
- //proverka za []!
- if (comand[0] == '!' && comand[comand.Length - 1] == '!')//ako parviq i poslediq 4arsa !
- {
- comandSub = comand.Substring(1, comand.Length - 2);//vzimame stringa ot parvi do opredelena daljina do pred posledniq
- if (comandSub.Length >= 3)
- {
- if (char.IsLower(comandSub[0]))//dali parviq char e glavna bukva
- {
- comandore = false;
- }
- for (int j = 1; j < comandSub.Length; j++)
- {
- if (char.IsUpper(comandSub[j]))
- {
- comandore = false;
- break;
- }
- }
- }
- else
- {
- comandore = false;
- }
- }
- else
- {
- comandore = false;
- }
- string decript = splitedInput[1];
- if (decript[0] == '[' && decript[decript.Length - 1] == ']')
- {
- string decriptSub = decript.Substring(1, decript.Length - 2);
- if (decriptSub.Length >= 8)
- {
- for (int k = 0; k < decriptSub.Length; k++)
- {
- if (char.IsLetter(decriptSub[k]))//preverqvame teksta dali e ot bukvi
- {
- int curentnum = decriptSub[k];
- numbers.Add(curentnum);//ako e ot bukvi ima vzimame stoinosti
- }
- else
- {
- dec = false;
- break;
- }
- }
- }
- else
- {
- dec = false;
- }
- }
- else
- {
- dec = false;
- }
- }
- else
- {
- comandore = false;
- }
- if (comandore && dec)
- {
- Console.WriteLine($"{comandSub}: {string.Join(" ", numbers)} ");
- }
- else
- {
- Console.WriteLine($"The message is invalid");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement