Advertisement
Guest User

04 Split by Word Casing

a guest
Jun 12th, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04_Split_By_Word_Casing
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split(new char[]
  12.             { ',', ';', ':', '.', '!', '(', ')', '"', '\\', '/', '[', ']', ' ' },
  13.             StringSplitOptions.RemoveEmptyEntries).ToList();
  14.  
  15.             List<string> lowerCase = new List<string>();
  16.             List<string> mixedCase = new List<string>();
  17.             List<string> upperCase = new List<string>();
  18.  
  19.             foreach (string word in input)
  20.             {
  21.                 int lowerCaseLetters = 0;
  22.                 int upperCaseLetters = 0;
  23.  
  24.                 foreach (char letter in word)
  25.                 {
  26.                     if (char.IsLower(letter))
  27.                     {
  28.                         lowerCaseLetters++;
  29.                     }
  30.                     else if (char.IsUpper(letter))
  31.                     {
  32.                         upperCaseLetters++;
  33.                     }
  34.                 }
  35.  
  36.                 if (lowerCaseLetters != word.Length && upperCaseLetters != word.Length)
  37.                 {
  38.                     mixedCase.Add(word);
  39.                 }
  40.                 else if (lowerCaseLetters == word.Length)
  41.                 {
  42.                     lowerCase.Add(word);
  43.                 }
  44.                 else
  45.                 {
  46.                     upperCase.Add(word);
  47.                 }
  48.             }
  49.             Console.WriteLine("Lower-case: " + string.Join(", ", lowerCase));
  50.             Console.WriteLine("Mixed-case: " + string.Join(", ", mixedCase));
  51.             Console.WriteLine("Upper-case: " + string.Join(", ", upperCase));
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement