ssu 486. "Bulls and Cows"

486. "Bulls and Cows"
Time limit per test: 0.25 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard




You probably know the game "bulls and cows". Just in case, we explain the rules. The first player picks a four-digit number with all digits distinct (leading zero is allowed) and keeps it secret. The second player tries to guess the secret number. For each guess, the first player issues a response in the form "n bulls, m cows". A "bull" is a digit that is present in both the secret and the guess and occurs in the same position in both. A "cow" is a digit that is present in both numbers, but occurs in different positions.

For example, if the first player picked 5071, and the second guessed 6012, the response would be "one bull, one cow". Here the "bull" is the digit 0, as it is in the second position in both numbers, and the "cow" is the digit 1, as it is in the fourth position in the secret, but in the third position in the guess.

Write a program to count the number of cows and bulls for the given the secret and guess.

Input

The first line of the input file contains four digits, the number picked by the first player. The second line contains the number guessed by the second player in the same format.

Output

The first and only line of the output file should contain two integers separated by a space, the number of "bulls" and the number of "cows".

Example(s)
sample input
sample output
5071
6012
1 1

 

sample input
sample output
4321
4321
4 0

 

sample input
sample output
1980
0879
0 3

 

sample input
sample output
1234
5678
0 0

 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <cmath>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
#include <string>
#define LL long long
#define maxn 100010
#define mod 1000000007
#define INF 2000000
#define MAX 16000010
#define eps 1e-6
using namespace std;

int main()
{
    int i ,m , tt , j , n ;
    int num[10] ,x , y ;
    char a[6] , b[6] ;
     // freopen("in.txt","r",stdin) ;
    // 水题、、、、
    while( scanf("%s%s",a,b) != EOF)
    {
        memset(num,0,sizeof(num)) ;
        x = y = 0 ;
        for( i = 0 ; i < 4 ;i++)
        {
            num[a[i]-'0']++ ;
            if(a[i]==b[i])
            x++ ;
        }
        for( i = 0 ; i < 4 ;i++) if(a[i] != b[i] && num[b[i]-'0'])
            y++ ;
        cout << x << " " << y << endl;
    }
    return 0 ;
}

 

转载于:https://www.cnblogs.com/20120125llcai/p/3596526.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值