Advertisement
Spocoman

Name Game

Sep 21st, 2023
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string name, winner = "";
  8.     getline(cin , name);
  9.  
  10.     int num, points = 0;
  11.  
  12.     while (name != "Stop") {
  13.         int sum = 0;
  14.         for (int i = 0; i < name.length(); i++) {
  15.             cin >> num;
  16.             int z = name[i];
  17.  
  18.             if (num == z) {
  19.                 sum += 10;
  20.             }
  21.             else {
  22.                 sum += 2;
  23.             }
  24.         }
  25.  
  26.         if (sum >= points) {
  27.             winner = name;
  28.             points = sum;
  29.         }
  30.         cin.ignore();
  31.         getline(cin, name);
  32.     }
  33.     cout << "The winner is " << winner << " with " << points << " points!\n";
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement