Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
1
Indexable
Never
#include <iostream>
#include <string>
#include <map>
#include <limits.h>
using namespace std;

int main(){
    int maxRate = INT_MIN;
    string maxMovie = "";
    map<string, int> movieRatings;
    
    string input;
    
    while(true){
        
        getline(cin, input);
        
        if(input == "THE END")
            break;
        
        int pos = input.find(" # ");
        string movie = input.substr(0, pos);
        int rating = stoi(input.substr(pos+3)); 
        
        if(movieRatings.find(movie) != movieRatings.end()){
            movieRatings[movie] += rating;
        }else{
            movieRatings[movie] = rating;
        }
        
        
    }
    
    
    for (const auto& pair : movieRatings) {
        if(pair.second > maxRate){
            maxRate = pair.second;
            maxMovie = pair.first;
        }
//        else if((pair.second == maxRate) && (pair.first < maxMovie)){
//            maxRate = pair.second;
//            maxMovie = pair.first;
//        }
    }
    

    cout  << maxMovie << " " << maxRate ;
    return 0;
}
    
Leave a Comment