View Code of Problem 100

#include <iostream>
#include <stdio.h>
#include<string>
#include<algorithm>
using namespace std;

struct Song{
  string name;
  int s,f;//总时长
  int score=0;
};

bool comp(Song song1,Song song2)
{
    if(song1.score!=song2.score){
        return song1.score>song2.score;
    }else{
        return song1.name<song2.name;
    }
}
int main(){
    int n,m;
    char c = ':';
    //1
    while(cin>>n){
        if(n==0) return 0;
        Song song[n];
        for(int i=0;i<n;i++){
            cin>>song[i].name>>song[i].s>>c>>song[i].f;
        }

        /*for(int i=0;i<n;i++){
            cout<<song[i].name<<" "<<song[i].s<<":"<<song[i].f<<endl;
        }*/
        //2
        cin>>m;
        Song song_history;//最近听的歌
        for(int h=0;h<m;h++){

            cin>>song_history.name>>song_history.s>>c>>song_history.f;
            for(int i=0;i<n;i++){
                if(song_history.name == song[i].name){
                    double song_time = song[i].s*60 + song[i].f;
                    //cout<<song_time<<endl;
                    double song_history_time = song_history.s*60 + song_history.f;
                    //cout<<song_history_time<<endl;
                    double score1 = song_history_time / song_time;
                    //cout<<score1<<endl;
                    if(score1<0.2){
                        ;
                    }
                    else if(score1>=0.2 && score1<0.4){
                        song[i].score += 1;
                    }
                    else if(score1>=0.4 && score1<0.6){
                        song[i].score += 2;
                    }
                    else if(score1>=0.6 && score1<0.8){
                        song[i].score += 3;
                    }
                    else if(score1>=0.8 && score1<1.0){
                        song[i].score += 4;
                    }
                    else if(score1 == 1.0){
                        song[i].score += 5;
                    }
                    //cout<<i<<endl;
                }
            }
        }

        sort(song,song+n,comp);

        for(int i=0;i<n;i++){
            cout<<song[i].name<<" "<<song[i].score<<endl;
        }


    }

    return 0;
}

Double click to view unformatted code.


Back to problem 100