madeofglass

fm

Feb 24th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06.FavoriteMovie
  4. {
  5.     class FavoriteMovie
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string movieName = Console.ReadLine();
  10.  
  11.             int counter = 0;
  12.             string bestMovie = "";
  13.             int sumMovie = 0;
  14.  
  15.  
  16.             while (movieName != "STOP")
  17.             {
  18.                 int sum = 0;
  19.                 counter++;
  20.  
  21.                 if (counter > 7)
  22.                 {
  23.                     Console.WriteLine("The limit is reached.");
  24.                     break;
  25.                 }
  26.  
  27.                 for (int i = 0; i < movieName.Length; i++)
  28.                 {
  29.                     if (Char.IsUpper(movieName[i]))
  30.                     {
  31.                         sum += movieName[i] - movieName.Length;
  32.                     }
  33.                     else if (Char.IsLower(movieName[i]))
  34.                     {
  35.                         sum += movieName[i] - 2 * movieName.Length;
  36.                     }
  37.                     else
  38.                     {
  39.                         sum += movieName[i];
  40.                     }
  41.                 }
  42.                                
  43.                 if (sum > sumMovie)
  44.                 {
  45.                     sumMovie = sum;
  46.                     bestMovie = movieName;
  47.                 }
  48.  
  49.                 movieName = Console.ReadLine();
  50.             }
  51.  
  52.             Console.WriteLine($"The best movie for you is {bestMovie} with {sumMovie} ASCII sum.");
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment