ZOJ 1057 Undercut(简单模拟)

时间:2021-05-10 12:29:46

Undercut

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=57

题目大意:a card game,two player,每个player有n张牌,按顺序出牌,如果2张牌的点数相等,2个player都不得分;如果2张牌点数相差1,点数大的player得分为2张牌的点数和;如果2张牌的点数相差超过1,点数大的player得分为点数大的牌的点数;特殊情况,如果2张牌的点数分别为1和2,持2的player得分为6而不是3;给出2个player各n张牌的点数,要求输出每个player的得分情况

代码如下:

 # include<stdio.h>
# include<string.h>
int main(){
bool first = true;
int n,i;
int a[],b[];
while(scanf("%d",&n) && n){
if(!first) puts("");
for(i=; i<n; i++)
scanf("%d", &a[i]);
for(i=; i<n; i++)
scanf("%d", &b[i]);
int suma = ,sumb=;
for(i=; i<n; i++){
if(a[i]== && b[i]==){
suma += ;
continue;
}
if(a[i]== && b[i]==){
sumb += ;
continue;
}
if(a[i]==b[i]) continue;
if(a[i] - b[i] == ){
sumb += (a[i]+b[i]);
continue;
}
if(b[i] - a[i] == ){
suma += (a[i]+b[i]);
continue;
}
if(a[i]>b[i]) suma += a[i];
if(b[i]>a[i]) sumb += b[i];
}
printf("A has %d points. B has %d points.\n",suma,sumb);
first = false;
}
return ;
}