Advertisement
georgimanov

Problem 14. Longest Word in a Text

Apr 13th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. /*
  2. Problem 14. Longest Word in a Text
  3. Write a program to find the longest word in a text. Examples:
  4. Input   Output
  5. Welcome to the Software University. University
  6. The C# Basics course is awesome start in programming with C# and Visual Studio. programming
  7. */
  8.  
  9. using System;
  10.  
  11. class LongestWordInText
  12. {
  13.     static void Main(string[] args)
  14.     {
  15.         string text = Console.ReadLine();
  16.  
  17.         string[] arr = text.Split(new char[] { ' ', '.', ',', '!', '"', }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.         string temp = "";
  20.  
  21.         for (int write = 0; write < arr.Length; write++)
  22.         {
  23.             for (int sort = 0; sort < arr.Length - 1; sort++)
  24.             {
  25.                 if (arr[sort].Length > arr[sort + 1].Length)
  26.                 {
  27.                     temp = arr[sort + 1];
  28.                     arr[sort + 1] = arr[sort];
  29.                     arr[sort] = temp;
  30.                 }
  31.             }
  32.         }
  33.         Console.WriteLine(arr[arr.Length - 1]);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement