Advertisement
AvengersAssemble

Smarty

Jan 24th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Smarty
  7. {
  8.     class Program
  9.     {
  10.         public static string MinimizeString(string sentence)
  11.         {
  12.             string newSentence, lastWord, word;
  13.             newSentence = lastWord = word = "";
  14.             for (int i = 0; i < sentence.Length; i++)
  15.             {
  16.                 if (sentence[i] != ' ')
  17.                     word += sentence[i];
  18.                 if (sentence[i] == ' ' || i + 1 == sentence.Length)
  19.                 {
  20.                     if (lastWord != word)
  21.                         newSentence += word +" ";
  22.                     lastWord = word;
  23.                     word = "";
  24.                 }
  25.             }
  26.             return newSentence;
  27.         }
  28.         static void Main(string[] args)
  29.         {
  30.             string sent;
  31.             Console.WriteLine("Sentence: ");
  32.             sent = Console.ReadLine();
  33.             Console.WriteLine(MinimizeString(sent));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement