URAL 1804 The Machinegunners in a Playoff(模拟比赛得分)

来源:互联网 发布:java二级考试题库下载 编辑:程序博客网 时间:2024/06/05 10:16

1804. The Machinegunners in a Playoff

Time limit: 0.5 second
Memory limit: 64 MB
The Machinegunners women's football team has advanced to the knockout stage of the Revolution Cup. The Cavalry team is their opponent in the first round.
According to the rules, the teams must play two games, one at the Machinegunners' stadium and the other at the Cavalry's stadium. The team that scores more goals in the two games will advance to the next round. If the teams score the same number of goals, then the team that scores more goals at the opponent's stadium will advance. If these numbers are also the same, then the winner will be chosen at random.
The teams have played their first game already. The Machinegunners want to work out an adequate tactics for the return game, and for this they need to know the following two values:
  • the minimal number of goals they must score to get a chance to advance to the next round;
  • the maximal number of goals they may score which leaves a chance for their opponents to advance to the next round.
It is known that no team can score more than thirty goals in one game.

Input

The input consists of several test cases. The first line contains the number of test cases t (1 ≤ t≤ 200). Each of the following t lines describes one test case and contains the result of the first game in the form:
The Machinegunners played where game, scored x goals, and conceded y goals.
where where is the string “home” or “away”; 0 ≤ xy ≤ 30.

Output

For each of test cases output in a separate line the minimal number of goals necessary to advance to the next round and the maximal number of goals that does not guarantee this.

Sample

inputoutput
2The Machinegunners played home game, scored 28 goals, and conceded 0 goals.The Machinegunners played home game, scored 1 goals, and conceded 1 goals.
0 11 29

题意:

判断让自己赢的最小的自己的得分和让对方赢得的自己的最大得分,如果总得分情况一样,就看客场得分的情况。

AC代码:

#include <cstdio>#include <iostream>using namespace std;int main(){int t,x,y,flag,i;char a[152];scanf("%d",&t);getchar();while(t--){cin.getline(a,150);flag=1;for(i=43;i<150;i++){if(a[i]>='0'&&a[i]<='9'){if(flag){x=a[i]-'0';if(a[i+1]>='0'&&a[i+1]<='9'){x=x*10+a[i+1]-'0';i++;}flag=0;}else{y=a[i]-'0';if(a[i+1]>='0'&&a[i+1]<='9')y=y*10+a[i+1]-'0';break;}}}if(a[26]=='h'){if(x==0){if(y==0)printf("0 29\n");elseprintf("%d 30\n",y);}else if(x==30){if(y==30)printf("1 30\n");elseprintf("0 %d\n",y);}else{if(x==y)printf("1 29\n");else if(x<y)printf("%d 30\n",y-x+1);elseprintf("0 %d\n",30+y-x-1);}}else if(a[26]=='a'){if(x==y)printf("0 30\n");else if(x<y)printf("%d 30\n",y-x);elseprintf("0 %d\n",30+y-x);}}return 0;}


0 0
原创粉丝点击