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 :)
#include <iostream>
#include <string.h>
using namespace std;
int main(){
int N,G,S,C,M,i,j;
char a[150][15];
while(cin>>N){
cin>>G>>S;
cin>>C>>M;
if(N==0&&G==0&&S==0&&C==0&&M==0)
break;
for(i=0;i<N;i++)
cin.getline(a[i],15);
int b[150]={0},k=1;
for(i=0;i<N;i++){
for(j=0;a[i][j]!=' ';j++)
b[i]=b[i]*10+a[i][j]-'0';}
for(i=0;i<N;i++){
if(b[i]>b[M-1])
k++;
if(b[i]==b[M-1]&&strcmp(a[i],a[M-1])<0)
k++;}
if(k<=G)
cout<<"Accepted today? I've got a golden medal :)"<<endl;
else if(k-G<=S&&k-G>0)
cout<<"Accepted today? I've got a silver medal :)"<<endl;
else if(k-G-S<=C&&k-G-S>0)
cout<<"Accepted today? I've got a copper medal :)"<<endl;
else
cout<<"Accepted today? I've got an honor mentioned :)"<<endl;}}
找錯
uj5u.com熱心網友回復:
我怎么覺得你的程式思路就不對啊,還是我英文理解不對?應該要算出答題的平均時間吧,要不然每行的答題數就沒意義了。
uj5u.com熱心網友回復:
?每一行是不同選手的吧uj5u.com熱心網友回復:
比較各個答題選手,M是指第幾名選手
uj5u.com熱心網友回復:
不應該先比答題數,相同再比時間嗎
uj5u.com熱心網友回復:
M是第幾名選手,gsc是獎牌數,N是參賽人數我知道,只是沒看明白要找出M的排名的規則(答題數和答題時間有什么意義),所以覺得要算平均答題時間,否則比如答10題需要24小時,答1題需要3小時,到底誰算第一?uj5u.com熱心網友回復:
你的問題錯誤在于過于相信自己的輸入輸出本事了cin>>M; 之后,回車依然在緩沖區內
接下來的getline獲得的第一組資料是就是個回車,換句話說就是個空行
所以后面都錯了
uj5u.com熱心網友回復:
原文沒有給出M是是個什么意思根據樓主的說法M是就是要判斷第M行的那個資料,能得什么獎牌
每行的p越大越排在前面,后面的時間越小越排在后面
樓主在b陣列當中,把p弄成整數了
用k來記錄M排第幾, 默認是第一
然后回圈看, 如果有b陣列記錄的p對應的人比M的p值高,則k++,也就是M排名降低一位
如果兩者p相同, 時間比M小, M排名再降低一位
大概就是這個意思
錯誤再getline讀取資料就錯了, 糾結后面的演算法沒用
uj5u.com熱心網友回復:
在cin>>M;之后按照你的代碼風格,加一句
cin>>getline(a[0], 15); 空跑一行把緩沖區的回車提取出來就解決問題了
uj5u.com熱心網友回復:
謝謝..........uj5u.com熱心網友回復:
ac了。。。。。。。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/140764.html
標籤:C++ 語言
上一篇:對我之前未結的scanf進行補充
下一篇:麻煩大佬們看下
