HDU 1177 Accepted today? 利用sort排序字符串,出现WA

HDU 1177 Accepted today? 利用sort排序字符串,出现WA

题目如下
简述为:输入 参赛人数 金牌数 银牌数 铜牌数 您是第几个 以及各个数据,输出你获得的奖牌是什么。
排列规则为,通过题目数目越多,排名越高,相同情况下,时间短的排名高。

“Accepted today?”
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3734 Accepted Submission(s): 1646

Problem Description
Do you remember a sentence “Accepted today?” Yes, the sentence is mentioned frequently in lcy’s course “ACM Programming”!
The contest is still in progress this moment. How excited it is! You, smart programmer, must have AC some problems today. “Can I get copper medal, silver medal, or even golden medal?” Oh, ha-ha! You must be considering this question. And now, the last problem of this contest comes.
Give you all submitting data in the contest, and tell you the number of golden medals, silver medals and copper medals; your task is to output someone’s contest result.
Easy? Of course! I t is the reason that I designed the problem.
When you have completed this contest, please remember that sentence〃 Accepted today?〃兒

Input
Input contains multiple test cases. Each test case starts with five numbers N (4 =< N <= 130 – the total number of attendees), G, S, C (1<=G<=S<=C<N --G, S, C denoting the number of golden medals, silver medals and copper medals respectively) and M (0<M<=N). The next N lines contain an integer P (1<=P<=8 --number of problems that have been solved by someone) and a time T(for example,“02:45:17”, meaning 2 hours and 45 minutes and 17 seconds consumed according to contest rules) each. You can assume that all submit data are different.
A test case starting with 0 0 0 0 0 terminates input and this test case should not to be processed.

Output
For each case, print a sentence in a line, and it must be one of these sentences:
Accepted today? I’ve got a golden medal 😃
Accepted today? I’ve got a silver medal 😃
Accepted today? I’ve got a copper medal 😃
Accepted today? I’ve got an honor mentioned 😃

Note:
You will get an honor mentioned if you can’t get copper medal, silver medal or golden medal.

Sample Input
10 1 2 3 6
2 02:45:17
2 02:49:01
2 03:17:58
2 03:21:29
4 07:55:48
3 04:25:42
3 06:57:39
2 02:05:02
2 02:16:45
2 02:41:37
0 0 0 0 0

Sample Output
Accepted today? I’ve got a silver medal 😃

我的想法如下
用string数组存储数据,用sort降序排列,使得通过题目多排名靠前。
在对string[0]相同的string数组进行升序排列,让时间短的排名靠前。
我的代码如下,注意,在oj平台上提交wa,求大佬指出问题所在。
(输出“\n”不影响)

#include<bits/stdc++.h>
using namespace std;
static string str[1000],R;
int main(){
	
	int num,gn,sn,cn,my,Rank=1;
	cin>>num>>gn>>sn>>cn>>my;
	cin.ignore(1,'\n');
	for(int i=0;i<=num;i++) {
		getline(cin,str[i]);
	}
	R=str[my-1];
	sort(str,str+num,greater<string>()); //降序排列 
	
	
	char t=str[0][0];int n=1;
	for(int i=1;i<num;i++){
		t=str[i][0];
		if(t==str[i-1][0])n++;
		else{
			sort(str+i-n,str+i,less<string>());
			n=1;
		}
	}
	if(n>1)sort(str+num-n,str+num);
	for(int i=0;i<num;i++){
		if(R==str[i])break;
		Rank++;
	}
	if(Rank<=gn)cout<<cout <<"Accepted today? I've got a golden medal :)\n";
	else {
		if(Rank<=gn+sn)cout <<"Accepted today? I've got a silver medal :)\n";
		else{
			if(Rank<=gn+sn+cn)cout<<"Accepted today? I've got a copper medal :)\n";
			else cout <<"Accepted today? I've got an honor mentioned :)\n";
		}
	}



}

求大佬解答

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值