Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _23UniqueLetters
  8. {
  9.     class UniqueLetters
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string sample = "ala bala nica, ABBA aaaaaataka boobs mississippi";
  14.             StringBuilder sb = new StringBuilder();
  15.             char lastAppended = char.MinValue;
  16.  
  17.             for (int i = 0; i < sample.Length; i++)
  18.             {
  19.                 char currentSymbol = sample[i];
  20.                 if (('a' <= currentSymbol || currentSymbol <= 'z') || ('A' <= currentSymbol || currentSymbol <= 'Z'))
  21.                 {
  22.                     if (currentSymbol != lastAppended)
  23.                     {
  24.                         sb.Append(currentSymbol);
  25.                         lastAppended = currentSymbol;
  26.                     }
  27.                 }
  28.                 else
  29.                 {
  30.                     sb.Append(currentSymbol);
  31.                 }
  32.             }
  33.             Console.WriteLine(sb.ToString());
  34.  
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement