fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int first,second,bulls = 0,cows = 0;
  6. cin>>first>>second;
  7. int one[4],two[4];
  8. for(int i =0;i<4;i++){
  9. one[i] = first%10;
  10. first = first/10;
  11. two[i] = second%10;
  12. second = second/10;
  13. if(one[i] == two[i])
  14. bulls++;
  15. }
  16. if(two[0]==one[1]||two[0]==one[2]||two[0]==one[3])
  17. cows++;
  18. if(two[1]==one[0]||two[1]==one[2]||two[1]==one[3] )
  19. cows++;
  20. if(two[2]==one[0]||two[2]==one[1]||two[2]==one[3])
  21. cows++;
  22. if(two[3]==one[0]||two[3]==one[1]||two[1]==one[2] )
  23. cows++;
  24. cout<<bulls<< ' '<< cows<<endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5316KB
stdin
1234
5678
stdout
0 0