Advertisement
AvengersAssemble

StringStuff

Apr 3rd, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             char character = 'a';
  4.             int nextIndex = 0, wordsCount, characterCount = 0;
  5.             string lastLetters = "", sentence, lastLettersCopy;
  6.             sentence = Console.ReadLine();
  7.             while (nextIndex != -1)
  8.             {
  9.                 nextIndex = sentence.IndexOf(" ", nextIndex) + 1;
  10.                 if (nextIndex == 0)
  11.                     nextIndex--;
  12.                 else
  13.                     lastLetters += sentence[nextIndex - 2];
  14.             }
  15.             lastLetters += sentence[sentence.Length - 2];
  16.             for (int i = 0; i < 26; i++)
  17.             {
  18.                 lastLettersCopy = lastLetters;
  19.                 lastLettersCopy = lastLettersCopy.Replace(((char)('a' + i)).ToString(), "");
  20.                 if (lastLetters.Length - lastLettersCopy.Length > characterCount)
  21.                 {
  22.                     characterCount = lastLetters.Length - lastLettersCopy.Length;
  23.                     character = (char)('a' + i);
  24.                 }
  25.             }
  26.             Console.WriteLine(character);
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement