Seal_of_approval

Pr8R3ex16

Oct 23rd, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4.  
  5. namespace test
  6. {
  7.     class Program
  8.     {
  9.         static int ifMarks (char a, char [] m)
  10.         {
  11.             int x = 0;
  12.             for (int i = 0; i < m.Length; i++)
  13.                 if (a == m [i])
  14.                     x += 1;
  15.             return x;
  16.         }
  17.  
  18.         static void Main()
  19.         {
  20.             string a = Console.ReadLine ();
  21.             StringBuilder str = new StringBuilder (a);
  22.             char[] marks = { '.', '?', '!', ';', ':', ',' };
  23.             int i = 0;
  24.             while (i != str.Length - 1) {
  25.                 int k = i + 1;
  26.                 if (ifMarks (str [k], marks) == 1 && str [k - 1] == ' ') {
  27.                     str.Remove (k - 1, 1);
  28.                     i -= 2;
  29.                 }
  30.                 if (ifMarks (str [i], marks) == 1 && str [i + 1] != ' ') {
  31.                     str.Insert (i + 1, ' ');
  32.                     i++;
  33.                 }
  34.  
  35.                 i++;
  36.             }
  37.             Console.WriteLine ("New string = {0}", str);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment