Advertisement
Spocoman

06. Replace Repeating Chars

Apr 15th, 2023
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace ReplaceRepeatingChars
  7. {
  8.  
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             string str = Console.ReadLine();
  14.             var result = new StringBuilder();
  15.             result.Append(str[0]);
  16.  
  17.             for (int i = 1; i < str.Length; i++)
  18.             {
  19.                 if (str[i] != result[^1])
  20.                 {
  21.                     result.Append(str[i]);
  22.                 }
  23.             }
  24.  
  25.             Console.WriteLine(result);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement