Advertisement
Guest User

P06

a guest
Mar 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace _06ReplaceRepeatingChars
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string text = Console.ReadLine();
  11.  
  12.             StringBuilder sb = new StringBuilder();
  13.  
  14.             for (int i = 0; i < text.Length - 1; i++)
  15.             {
  16.                 char currentCharacter = text[i];
  17.                 char nextCharacter = text[i + 1];
  18.  
  19.                 if (currentCharacter != nextCharacter)
  20.                 {
  21.                     sb.Append(currentCharacter);
  22.                 }
  23.  
  24.                 if (i == text.Length - 2)
  25.                 {
  26.                     sb.Append(nextCharacter);
  27.                 }
  28.             }
  29.  
  30.             Console.WriteLine(sb);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement