1087: Undercut
| Status | In/Out | TIME Limit | MEMORY Limit | Submit Times | Solved Users | JUDGE TYPE |
|---|---|---|---|---|---|---|
| stdin/stdout | 3s | 8192K | 2264 | 657 | Standard |
For example, if there are 5 rounds and player A plays (in this order) 5, 3, 1, 3, 5 and player B plays 3, 3, 3, 3, 4, then the scoring for each round would be: A gets 5 points, no points, B gets 3 points, no points, B gets 9 points. The totals would be A: 5, B: 12.
In this problem you will be given card plays for both players and must determine the final scores.
Input
There will be multiple input instances. Each instance will be one game. The first line of input for a game will be an integer n <= 20. (A value of n = 0 terminates input.) The next two lines will each contain n integers between 1 and 5 inclusive indicating the cards played on each of n rounds. The first line are player A's card plays and the second line are player B's card plays.
Output
Each input instance should generate one line of output of the form:
A has a points. B has b points.
where the value of a and b are for you to determine. A blank line should separate output lines.
Sample Input
5 5 3 1 3 5 3 3 3 3 4 4 2 3 1 1 1 5 5 5 0
Sample Output
A has 5 points. B has 12 points. A has 0 points. B has 21 points.
#include<stdio.h>
int main()
{
int n,i,m=0;
int a[21],b[21];
while(scanf("%d",&n),n)
{
if(m==0) m++;
else
printf("/n");
int count_a=0,count_b=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
if(a[i]==1&&b[i]==2) count_a+=6;
else if(a[i]==2&&b[i]==1) count_b+=6;
else if(a[i]<b[i]&&(b[i]-a[i])==1) count_a+=(a[i]+b[i]);
else if(a[i]<b[i]&&(b[i]-a[i])!=1) count_b+=b[i];
else if(a[i]>b[i]&&(a[i]-b[i])==1) count_b+=(a[i]+b[i]);
else if(a[i]>b[i]&&(a[i]-b[i])!=1) count_a+=a[i];
else ;
}
printf("A has %d points. B has %d points./n",count_a,count_b);
}
return 0;
}
本文介绍了一款名为Undercut的两人卡片游戏及其计分规则,并提供了一个C语言实现的例子,用于计算玩家在多轮游戏后的得分。
1229





