你使用什么音乐播放器,iTunes、千千静听、酷狗、Winamp 还是 WMP?这些主流的播放器都有一个叫“我的最爱”(也有叫 Top 50 等其他名字)的动态播放列表,里面列出播放次数最多的前 50 首歌曲。
但我觉得,简单地用播放次数作为喜欢的标准是不够准确的。有些歌曲在唱完以后还有一段很长的伴奏,我普遍会直接点“下一首”来跳过,但这样播放器就 认为这首歌没有播放完毕,所以播放次数没有增加,但其实这首歌“几乎”播放完了;另一些歌是我不喜欢听的,可能只播放了前奏我就直接切歌了。所以,仅仅依 靠播放次数是无法区分上面两类歌曲我的喜好情况。
现在,我设计了一种新的统计方法:根据播放时间占总时间的百分比,给每次听歌打 0 到 5 分,最后通过总分来排序。
假设一首歌 ABC.mp3 长度是 01:40,即 100 秒。
输入
输入会有多组,每一组数据分两部分:
输出
根据前面介绍的规则,算出每首歌的得分,并按照得分倒序输出“歌曲的名字”和“得分”(中间用一个空格隔开)。如果有两首歌的得分一样,那就根据歌曲名字来排序(按照字典顺序)。
输入样例 1 点击复制
5 gala_young_for_you.mp3 03:39 Another_Day_In_Paradise.mp3 05:22 Don't_Cry_For_Me_Argentina.mp3 05:38 I'll_Never_Stop.mp3 03:07 U_Make_Me_Wanna.mp3 03:42 11 I'll_Never_Stop.mp3 03:00 gala_young_for_you.mp3 03:30 Another_Day_In_Paradise.mp3 05:21 I'll_Never_Stop.mp3 03:07 U_Make_Me_Wanna.mp3 03:00 gala_young_for_you.mp3 03:37 Another_Day_In_Paradise.mp3 05:20 U_Make_Me_Wanna.mp3 03:42 Don't_Cry_For_Me_Argentina.mp3 01:07 I'll_Never_Stop.mp3 03:05 Don't_Cry_For_Me_Argentina.mp3 01:08 0
输出样例 1
I'll_Never_Stop.mp3 13 U_Make_Me_Wanna.mp3 9 Another_Day_In_Paradise.mp3 8 gala_young_for_you.mp3 8 Don't_Cry_For_Me_Argentina.mp3 1
非常坏的题目,非常臭的代码
#include
#include
#include
struct aa { //总的名字,听的时间
char songs[100];
double time;
int score;
};
struct bb { //记录的名字,听的时间
char jl[100];
double ttime;
};
int cmp(const void *a, const void *b) {
struct aa *aa1 = (struct aa *)a;
struct aa *aa2 = (struct aa *)b;
// 先根据score排序
if (aa1->score != aa2->score) {
return aa2->score - aa1->score;
}
// 若score相同,则用songs排序
return strcmp(aa1->songs, aa2->songs);
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
struct aa a[101];
char temp[10];
memset(temp, '\0', sizeof(temp));
for (int i = 0; i < n; i++) {
scanf("%s %s", a[i].songs, temp);
a[i].time = ((temp[0] - '0') * 10 + (temp[1] - '0')) * 60 + ((temp[3] - '0') * 10 + (temp[4] - '0')); //秒数计算
a[i].score = 0;
}
int m;
scanf("%d", &m);
struct bb b[10005];
for (int i = 0; i < m; i++) {
scanf("%s %s", b[i].jl, temp);
b[i].ttime = ((temp[0] - '0') * 10 + (temp[1] - '0')) * 60 + ((temp[3] - '0') * 10 + (temp[4] - '0'));
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (strcmp(a[j].songs, b[i].jl) == 0) {
if (a[j].time == b[i].ttime)
a[j].score += 5;
else if (b[i].ttime >= a[j].time / 5 * 4 && b[i].ttime < a[j].time)
a[j].score += 4;
else if (b[i].ttime >= a[j].time / 5 * 3 && b[i].ttime < a[j].time / 5 * 4 + 1)
a[j].score += 3;
else if (b[i].ttime >= a[j].time / 5 * 2 && b[i].ttime < a[j].time / 5 * 3 + 1)
a[j].score += 2;
else if (b[i].ttime >= a[j].time / 5 && b[i].ttime < a[j].time / 5 * 2 + 1)
a[j].score += 1;
break;
}
}
}
qsort(a, n, sizeof(struct aa), cmp);
for (int i = 0; i < n; i++) {
printf("%s %d\n", a[i].songs, a[i].score);
}
}
}