Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- namespace test
- {
- class Program
- {
- static int ifMarks (char a, char [] m)
- {
- int x = 0;
- for (int i = 0; i < m.Length; i++)
- if (a == m [i])
- x += 1;
- return x;
- }
- static void Main()
- {
- string a = Console.ReadLine ();
- StringBuilder str = new StringBuilder (a);
- char[] marks = { '.', '?', '!', ';', ':', ',' };
- int i = 0;
- while (i != str.Length - 1) {
- int k = i + 1;
- if (ifMarks (str [k], marks) == 1 && str [k - 1] == ' ') {
- str.Remove (k - 1, 1);
- i -= 2;
- }
- if (ifMarks (str [i], marks) == 1 && str [i + 1] != ' ') {
- str.Insert (i + 1, ' ');
- i++;
- }
- i++;
- }
- Console.WriteLine ("New string = {0}", str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment