Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06._Favorite_Movie
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int limit = 0;
  10.  
  11.             string bestMovie = "";
  12.             int bestMovieSum = 0;
  13.  
  14.             int totalSum = 0;
  15.  
  16.             while (limit < 7)
  17.             {
  18.                 totalSum = 0;
  19.  
  20.                 string command = Console.ReadLine();
  21.  
  22.                 if (command == "STOP")
  23.                 {
  24.                     Console.WriteLine($"The best movie for you is {bestMovie} with {bestMovieSum} ASCII sum.");
  25.                     break;
  26.                 }
  27.  
  28.                 for (int i = 0; i < command.Length; i++)
  29.                 {
  30.                     if (command[i] == ' ')
  31.                     {
  32.                         totalSum += command[i];
  33.                     }
  34.                     if (command[i] >= 0 && command[i] <= 9)
  35.                     {
  36.                         totalSum += command[i];
  37.                     }
  38.                     if (command[i] >= 'a' && command[i] <= 'z')
  39.                     {
  40.                         totalSum += command[i] - (2 * command.Length);
  41.                     }
  42.                     if (command[i] >= 'A' && command[i] <= 'Z')
  43.                     {
  44.                         totalSum += command[i] - command.Length;
  45.                     }
  46.                 }
  47.  
  48.                 limit++;
  49.  
  50.                 if (totalSum > bestMovieSum)
  51.                 {
  52.                     bestMovie = command;
  53.                     bestMovieSum = totalSum;
  54.                 }
  55.             }
  56.  
  57.             if (limit == 7)
  58.             {
  59.                 Console.WriteLine("The limit is reached.");
  60.                 Console.WriteLine($"The best movie for you is {bestMovie} with {bestMovieSum} ASCII sum.");
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement