ZJGSU 2044 我的最爱

你使用什么音乐播放器,iTunes、千千静听、酷狗、Winamp 还是 WMP?这些主流的播放器都有一个叫“我的最爱”(也有叫 Top 50 等其他名字)的动态播放列表,里面列出播放次数最多的前 50 首歌曲。

但我觉得,简单地用播放次数作为喜欢的标准是不够准确的。有些歌曲在唱完以后还有一段很长的伴奏,我普遍会直接点“下一首”来跳过,但这样播放器就 认为这首歌没有播放完毕,所以播放次数没有增加,但其实这首歌“几乎”播放完了;另一些歌是我不喜欢听的,可能只播放了前奏我就直接切歌了。所以,仅仅依 靠播放次数是无法区分上面两类歌曲我的喜好情况。

现在,我设计了一种新的统计方法:根据播放时间占总时间的百分比,给每次听歌打 0 到 5 分,最后通过总分来排序。

假设一首歌 ABC.mp3 长度是 01:40,即 100 秒。

  1. 如果某一次听歌我只听了 1-19 秒(少于 1/5),则本次得分为 0。
  2. 如果听了 20-39 秒,则得 1 分。
  3. 如果听了 40-59 秒,则得 2 分。
  4. 如果听了 60-79 秒,则得 3 分。
  5. 如果听了 80-99 秒,则得 4 分。
  6. 如果我耐心地听完整首歌(100秒),则得 5分。

输入

输入会有多组,每一组数据分两部分:

  1. 第一部分是歌曲信息列表
    1. 第一行是一个数字 n(0 <= n <= 100),表示后面会有 n 行歌曲信息。
    2. 接下来 n 行,每一行一条歌曲信息。包含歌曲的名字和总时间。
  2. 第二部分是我听歌记录的列表,格式和上面一样:
    1. 第一行是一个数字 m(0 <= m <= 10000),表示后面会有 m 行听歌记录。
    2. 接下来 m 行,每一行一条听歌记录。包含歌曲的名字和本次播放时间。
  3. 歌曲的名字里不会有空格,且长度不少过 30 个字符。
  4. 时间个格式是 mm:ss,即长度恒等于 5,分和秒用冒号隔开。时间最长不会超过 8分钟(又不是听相声)。
  5. 歌曲名字和时间中间用一个空格隔开。
  6. 当 n 等于 0 时,程序结束并退出。

输出

根据前面介绍的规则,算出每首歌的得分,并按照得分倒序输出“歌曲的名字”和“得分”(中间用一个空格隔开)。如果有两首歌的得分一样,那就根据歌曲名字来排序(按照字典顺序)。

输入样例 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);
		}
	}
}

你可能感兴趣的:(校园oj,c语言)