Assi

13. Strings and Text Processing 23. ReplaceIdenticalLetter

Jan 31st, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class ReplaceIdenticalLetter
  5. {
  6.  
  7.     static void Main()
  8.     {
  9.         List<string> str = new List<string> { "abc", "abbbbbcs", "abcddd", "aabc", "aabbcc" };
  10.  
  11.         for (int word = 0; word < str.Count; word++)
  12.         {
  13.             int wordLength = str[word].Length;
  14.             int countRemovedLetter = 1;
  15.             for (int letter = 0; letter < wordLength - countRemovedLetter; letter++)
  16.             {
  17.                 if (str[word].Substring(letter, 1) == str[word].Substring(letter + 1, 1))
  18.                 {
  19.                     str[word] = str[word].Remove(letter, 1);
  20.                     countRemovedLetter++;
  21.                     letter--;
  22.                 }
  23.             }
  24.         }
  25.         foreach (var item in str)
  26.         {
  27.             Console.WriteLine(item);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment