1057 Undercut

来源:互联网 发布:深圳资深淘宝 编辑:程序博客网 时间:2024/05/16 05:20

Undercut

Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 9696   Accepted Submit: 2267  

Undercut is a card game where two players each have five cards numbered one through five. At each round, each player selects a card, then simultaneously reveals it. If the cards are of equal value, there is no score. Otherwise, there are two cases: the two cards are exactly one point apart (this is called an undercut), or the cards are more than one point apart. In the latter case, the person revealing the larger of the cards gets the number of points on the larger card. In the case of an undercut the player with the lower card gets the sum of the two cards. The exception to this is when the cards are 1 and 2, in which case the player with the lower card gets 6 points (instead of only 3 points). After each round, the cards are returned to the hands and they play another round.

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.

http://acm.zju.edu.cn/show_problem.php?pid=1057 

 

#include <iostream>
using namespace std;

int aScore, bScore;
int Ca[1000], Cb[1000];
int n;

int check(int m, int n);
void solve();

int main()
{
    
int i;
    
int flag = 1;

    cin 
>> n;

    
while ( n != 0 )
    {
        aScore 
= 0;
        bScore 
= 0;
        
        
for ( i = 0; i < n; i++ )
            cin 
>> Ca[i];
        
for ( i = 0; i < n; i++ )
            cin 
>> Cb[i];

        
if ( flag == 0 )
            cout 
<< endl;
        solve();
    
        cin 
>> n;
        flag 
= 0;
    }

    
return 0;
}

int check(int m, int n)
{
    
if ( m - n == 1 )
    {
        
if ( m == 2 )
            
return 1;
        
else
            
return 2;
    }
    
else if ( n - m == 1 )
    {
        
if ( n == 2 )
            
return 3;
        
else
            
return 4;
    }
    
else if ( m - n >= 2 )
        
return 5;
    
else if ( n - m >= 2 )
        
return 6;
    
return 0;
}

void solve()
{
    
int i;

    
for ( i = 0; i < n; i++ )
    {
        
switch ( check(Ca[i], Cb[i]) )
        {
        
case 1: bScore += 6;
            
break;
        
case 2: bScore += (Ca[i] + Cb[i]);
            
break;
        
case 3: aScore += 6;
            
break;
        
case 4: aScore += (Ca[i] + Cb[i]);
            
break;
        
case 5: aScore += Ca[i];
            
break;
        
case 6: bScore += Cb[i];
            
break;
        
defaultcontinue;
        }
    }

    cout 
<< "A has " << aScore << " points. B has " 
        
<< bScore << " points.";
    cout 
<< endl;

}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 160平方房子装修图 法式风格装修效果图 85平米装修效果图 现代黑白灰装修效果图 80平房屋装修效果图 客厅墙面装修效果图 110平方装修效果图 手机店装修实体图 小洗手间装修效果图 不吊顶的客厅装修图 地中海风格装修效果图 平房客厅装修效果图 孕婴店装修效果图 小户型厨房装修效果图 联排别墅装修效果图 80平方的房子装修图 90平方房屋设计图 小平米装修效果图 新房子装修效果图 室内简单装修效果图大全 儿童卧室装修效果图小户型 小户型装修效果图大全2015图片 楼中楼装修效果图小户型 三室两厅装修效果图现代简约 现代装修风格效果图客厅 简约客厅装修实景图大全 90平方米简约装修效果图 190平方房子装修效果图 8平米卫生间装修效果图 100平方房屋装修效果图 四室两厅两卫装修效果图 130平米三室两厅装修效果图 八十平米小户型设计效果图 三室一厅一厨一卫装修效果图 七十平米小户型装修效果图 200平方米的房子设计图 75平方两室一厅装修效果图 113平方三室两厅装修效果图2015 85平米两室一厅装修效果图 四十平米小户型装修效果图 三房两厅两卫装修效果图