Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 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 _04.Split_by_Word_Casing
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> words = Console.ReadLine().Split(new[] { ',', ';', ':', '.', '!', '(', ')', '"', '\'', '\\', '/', '[', ']', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  14.             List<string> lowerCaseWords = new List<string>();
  15.             List<string> mixedCaseWords = new List<string>();
  16.             List<string> upperCaseWords = new List<string>();
  17.  
  18.             foreach(string word in words)
  19.             {
  20.                 if(word[0] >= 'a' && word[0] <= 'z')
  21.                 {
  22.                     bool isMixedCase = false;
  23.                     for(int i = 1; i<word.Length; i++)
  24.                     {
  25.                         if(word[i] < 'a' || word[i] > 'z')
  26.                         {
  27.                             isMixedCase = true;
  28.                         }
  29.                     }
  30.  
  31.                     if(isMixedCase)
  32.                     {
  33.                         mixedCaseWords.Add(word);
  34.                     }
  35.                     else
  36.                     {
  37.                         lowerCaseWords.Add(word);
  38.                     }
  39.                 }
  40.                 else if (word[0] >= 'A' && word[0] <= 'Z')
  41.                 {
  42.                     bool isMixedCase = false;
  43.                     for (int i = 1; i < word.Length; i++)
  44.                     {
  45.                         if (word[i] < 'A' || word[i] > 'Z')
  46.                         {
  47.                             isMixedCase = true;
  48.                         }
  49.                     }
  50.  
  51.                     if (isMixedCase)
  52.                     {
  53.                         mixedCaseWords.Add(word);
  54.                     }
  55.                     else
  56.                     {
  57.                         upperCaseWords.Add(word);
  58.                     }
  59.                 }
  60.                 else
  61.                 {
  62.                     mixedCaseWords.Add(word);
  63.                 }
  64.             }
  65.  
  66.             Console.WriteLine("Lower-case: {0}",string.Join(", ", lowerCaseWords));
  67.             Console.WriteLine("Mixed-case: {0}", string.Join(", ", mixedCaseWords));
  68.             Console.WriteLine("Upper-case: {0}", string.Join(", ", upperCaseWords));
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement