Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace FavoriteMovie
- {
- class Program
- {
- public static void Main()
- {
- string bestMovie = "";
- int asciiSum = 0;
- int counter = 0;
- string movie = Console.ReadLine();
- while (movie != "STOP" && counter != 7)
- {
- int currentAscii = 0;
- for (int j = 0; j < movie.Length; j++)
- {
- currentAscii += movie[j];
- if (movie[j] > 96 && movie[j] < 123)
- {
- currentAscii -= movie.Length * 2;
- }
- else if (movie[j] > 64 && movie[j] < 91)
- {
- currentAscii -= movie.Length;
- }
- if (currentAscii > asciiSum)
- {
- bestMovie = movie;
- asciiSum = currentAscii;
- }
- }
- counter++;
- movie = Console.ReadLine();
- }
- if (counter == 7)
- {
- Console.WriteLine("The limit is reached.");
- }
- Console.WriteLine($"The best movie for you is {bestMovie} with {asciiSum} ASCII sum.");
- }
- }
- }
- Решение с for:
- using System;
- namespace FavoriteMovie
- {
- class Program
- {
- public static void Main()
- {
- string bestMovie = "";
- int asciiSum = 0;
- bool isStop = false;
- for (int i = 0; i < 7; i++)
- {
- string movie = Console.ReadLine();
- if (movie == "STOP")
- {
- isStop = true;
- break;
- }
- int currentAscii = 0;
- for (int j = 0; j < movie.Length; j++)
- {
- currentAscii += movie[j];
- if (movie[j] > 96 && movie[j] < 123)
- {
- currentAscii -= movie.Length * 2;
- }
- else if (movie[j] > 64 && movie[j] < 91)
- {
- currentAscii -= movie.Length;
- }
- if (currentAscii > asciiSum)
- {
- bestMovie = movie;
- asciiSum = currentAscii;
- }
- }
- }
- if (isStop == false)
- {
- Console.WriteLine("The limit is reached.");
- }
- Console.WriteLine($"The best movie for you is {bestMovie} with {asciiSum} ASCII sum.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement