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的得分情况
代码如下:
1 # include<stdio.h> 2 # include<string.h> 3 int main(){ 4 bool first = true; 5 int n,i; 6 int a[20],b[20]; 7 while(scanf("%d",&n) && n){ 8 if(!first) puts(""); 9 for(i=0; i<n; i++) 10 scanf("%d", &a[i]); 11 for(i=0; i<n; i++) 12 scanf("%d", &b[i]); 13 int suma =0 ,sumb=0; 14 for(i=0; i<n; i++){ 15 if(a[i]==1 && b[i]==2){ 16 suma += 6; 17 continue; 18 } 19 if(a[i]==2 && b[i]==1){ 20 sumb += 6; 21 continue; 22 } 23 if(a[i]==b[i]) continue; 24 if(a[i] - b[i] == 1){ 25 sumb += (a[i]+b[i]); 26 continue; 27 } 28 if(b[i] - a[i] == 1){ 29 suma += (a[i]+b[i]); 30 continue; 31 } 32 if(a[i]>b[i]) suma += a[i]; 33 if(b[i]>a[i]) sumb += b[i]; 34 } 35 printf("A has %d points. B has %d points. ",suma,sumb); 36 first = false; 37 } 38 return 0; 39 }