Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- namespace ConsoleApp1
- {
- class Program
- {
- const int maxLineLength = 200;
- const string sentenceEnds = ".!?";
- const int minSentences = 3;
- const string punctuationSigns = ",:;-";
- static bool checkPunctuation(string line)
- {
- Regex punctuation = new Regex(@"^([A-ZА-Я]{1}\w*(,|:|;|-){0,1}(\s((\w+-\w+)+|\w+)(,|:|;|-){0,1})*((\w+-\w+)+|(\w+)){1}(\.\.\.|!|\?|\.){1}){3,}$");
- return punctuation.IsMatch(line);
- }
- /*static int calcLineSentences(string line)
- {
- string temp = string.Empty;
- int counter = 0;
- foreach (char symbol in line)
- {
- if (sentenceEnds.Contains(symbol) && temp.Length > 0)
- {
- temp = string.Empty;
- counter++;
- }
- else
- temp += symbol;
- }
- return counter;
- }
- static string[] getLineSentences(string line)
- {
- string[] sentences = new string[calcLineSentences(line)];
- string temp = string.Empty;
- int i = 0;
- foreach(char symbol in line)
- {
- if(sentenceEnds.Contains(symbol) && temp.Length > 0)
- {
- sentences[i++] = temp;
- temp = string.Empty;
- }
- else
- temp += symbol;
- }
- return sentences;
- }
- static bool checkSentences(string[] sentences)
- {
- bool isCorrect = sentences.Length >= minSentences;
- int i = 0;
- while(isCorrect && i < sentences.Length)
- {
- if (checkPunctuation(sentences[i]))
- i++;
- else
- isCorrect= false;
- }
- return isCorrect;
- }
- static bool checkLine(string line)
- {
- bool isCorrect = line.Length >= maxLineLength;
- return isCorrect & checkSentences(getLineSentences(line));
- }*/
- static string excludeEachNSymbol(string line, int N)
- {
- string cutLine = string.Empty;
- for (int i = 0; i < line.Length; i++)
- if ((i + 1) % N != 0)
- cutLine += line[i];
- return cutLine;
- }
- static void Main(string[] args)
- {
- Console.Write("Enter a line: ");
- string line = Console.ReadLine();
- if (line.Length <= maxLineLength && checkPunctuation(line))
- {
- if ((line.Length & 1) == 0)
- Console.Write(excludeEachNSymbol(line, 2));
- else
- Console.Write("The string is of odd length.");
- }
- else
- Console.Write("The string is not correct!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement