Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Smarty
- {
- class Program
- {
- public static string MinimizeString(string sentence)
- {
- string newSentence, lastWord, word;
- newSentence = lastWord = word = "";
- for (int i = 0; i < sentence.Length; i++)
- {
- if (sentence[i] != ' ')
- word += sentence[i];
- if (sentence[i] == ' ' || i + 1 == sentence.Length)
- {
- if (lastWord != word)
- newSentence += word +" ";
- lastWord = word;
- word = "";
- }
- }
- return newSentence;
- }
- static void Main(string[] args)
- {
- string sent;
- Console.WriteLine("Sentence: ");
- sent = Console.ReadLine();
- Console.WriteLine(MinimizeString(sent));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement