poj3589

来源:互联网 发布:临沂拓普网络拖欠工资 编辑:程序博客网 时间:2024/06/05 21:00

题目大意:

给出两个数,前一个数是X想的数,后一个数是Y猜的数,输出格式是A*B,A前面表示位置正确,值也正确的数量,B前的*表示值正确但是位置的数量

解题思路:

对比+遍历即可

代码如下:

#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){  char str1[5],str2[5];  int t,i,j;  int countp,countv;  scanf("%d",&t);  while(t--)  {    countp=countv=0;    scanf("%s%s",str1,str2);    for(i=0;i<4;i++)    {      if(str1[i]==str2[i])      {        countp++;      }      else      {        for(j=0;j<4;j++)        {          if(str1[i]==str2[j]&&(i!=j))          {            countv++;          }        }      }    }    printf("%dA%dB\n",countp,countv);  }  return 0;}
0 0