#1564: answer


1654469-2@g.puiching.edu.mo (P6D06吳奕恩)

School : No School
ID : 3054
IP address : [192.168.120.33]
Last Login :
2024-06-14 10:51:05
a009. 沒有手機的下課時間 -- 板橋高中教學題 | From: [192.168.120.33] | Post Date : 2024-05-22 11:28

#include<iostream>
using namespace std;

int main() 
{
  int num,times;
  while(cin>>num>>times)
  {
    for(int i=0;i<times;i++)
    {
      int guess;
      cin>>guess;
      int g[4],hold1=guess;
      for(int j=3;j>=0;j--)
      {
        g[j]=hold1%10;
        hold1=int(hold1/10);
      }
      int n[4],hold2=num;
      for(int j=3;j>=0;j--)
      {
        n[j]=hold2%10;
        hold2=int(hold2/10);
      }
      int a=0,b=0;
      for(int j=0;j<4;j++)
      {
        if(n[j]==g[j])
        a++;
        else
        {
          for(int k=0;k<4;k++)
          {
            if(g[j]==n[k]&&j!=k)
            b++;
          }
        }
      }
      cout<<a<<"A"<<b<<"B"<<endl;
    }
  }
  return 0;
}
 
ZeroJudge Forum