1. 程式人生 > 其它 >實驗九-結構體-火星人足球賽

實驗九-結構體-火星人足球賽

技術標籤:c++

【問題描述】

火星人足球賽的比賽規則與地球人的比賽規則有些非常相似,比如嚴重犯規,將被給予黃牌警告,特別嚴重的犯規,將給予紅牌直接罰下,如果有人得到第2張黃牌,則自動獲得紅牌罰下,比賽同樣採取主客場制。

與地球人足球賽不同的是,火星人足球賽每隊可以上場的人數不會固定為11人,可以多個人,比賽時間也會更長一些。

比賽時的裁判員是機器人,判罰非常嚴厲,如果有人獲得紅黃牌,機器人裁判將自動記錄當時的情況。

【輸入形式】

輸入的第一行為主隊隊名,第二行為客隊隊名,隊名的長度不超過20個字元。

第三行為一個整數 n (0 ≤ n ≤ 90) ,表示得到紅黃牌的犯規次數。

接下來的n行,每行包含用空格分隔的4個部分,表示犯規的情況:

首先為一個整數,表示犯規的時間(分鐘)

接著為一個字元"h"或"a",如果為"h",表示該張牌會給到主隊球員,否則會給到客隊球員

接下來為球員編號m (1 ≤ m ≤ 99)

接下來為一個字元"y"或"r",如果為"y",表示為黃牌,否則為紅牌

不同球隊的球員可能有相同的號碼,在同一球隊球員的號碼不相同,犯規記錄按時間順序排列。

【輸出形式】

輸出按時間順序排列的獲得紅牌的記錄,如果時間相同,則主隊排在前面,如果同一時間同一球隊有多人獲得紅牌,則編號大的排在前面。每個紅牌一行,包含3個部分:球員所屬球隊的名字、犯規球員編號、獲得紅牌時間。

如果全場比賽無紅牌,輸出"No Red Card"
【樣例輸入】

MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r
【樣例輸出】

MC 25 70
MC 42 82
CSKA 13 90
【樣例說明】
【評分標準】

在這裡插入圖片描述

#include<algorithm>
#include <iostream>
#include<string>
using namespace std;
struct Note{
    int
time;string team;int player;char card; }; bool cmp(Note a,Note b){ if(a.time==b.time){ if(a.team==b.team) { return a.player>b.player;} else {return a.team>b.team;} } else{ return a.time<b.time; } } int sum=0; int main(){ string Host_team;cin>>Host_team; string Gust_team;cin>>Gust_team; int n;cin>>n; Note *note=new Note[n]; for(int i=0;i<n;i++){ char temp; cin>>note[i].time; cin>>temp;if(temp=='h')note[i].team=Host_team; else{note[i].team=Gust_team;} cin>>note[i].player; cin>>note[i].card; } sort(note,note+n,cmp); for(int i=0;i<n;i++){ if(note[i].card=='r') {cout<<note[i].team<<" " <<note[i].player<<" " <<note[i].time<<endl; sum++;} if(note[i].card=='y'){ for(int j=i-1;j>=0;j--){ if(note[j].card=='y' &&note[j].player==note[i].player &&note[j].team==note[i].team) {cout<<note[i].team<<" " <<note[i].player<<" " <<note[i].time<<endl; sum++;} } } } if(sum==0){cout<<"No Red Card";} return 0; }