Advertisement
Spocoman

Favorite Movie

Sep 18th, 2023 (edited)
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string movie, bestMovie = "";
  8.     getline(cin, movie);
  9.  
  10.     int counter = 0, bestAscii = 0;
  11.  
  12.     while (movie != "STOP" && ++counter < 7) {
  13.         int currentAscii = 0;
  14.  
  15.         for (int j = 0; j < movie.length(); j++) {
  16.             currentAscii += movie[j];
  17.             if (movie[j] > 96 && movie[j] < 123) {
  18.                 currentAscii -= movie.length() * 2;
  19.             }
  20.             else if (movie[j] > 64 && movie[j] < 91) {
  21.                 currentAscii -= movie.length();
  22.             }
  23.         }
  24.         if (currentAscii > bestAscii) {
  25.             bestAscii = currentAscii;
  26.             bestMovie = movie;
  27.         }
  28.  
  29.         getline(cin, movie);
  30.     }
  31.  
  32.     if (counter == 7) {
  33.         cout << "The limit is reached.\n";
  34.     }
  35.     cout << "The best movie for you is " << bestMovie << " with " << bestAscii << " ASCII sum.\n";
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement