Advertisement
theo830

dsds

May 31st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int w1,w2;
  5. bool gaveOver(int guess[], int right[]){
  6. int totalRight = 0;
  7. int rightColor = 0;
  8. int grab;
  9. bool exclude[4];
  10. bool excludeColor[4];
  11. bool inList = false;
  12. for (int i = 0; i < 4; i++){
  13. exclude[i] = false;
  14. excludeColor[i] = false;
  15. }
  16. for (int i = 0; i < 4; i++)
  17. {
  18. if (guess[i] == right[i])
  19. {
  20. totalRight++;
  21. exclude[i] = true;
  22. }
  23. }
  24. for (int i = 0; i < 4; i++)
  25. {
  26. if (!exclude[i])
  27. {
  28. for (int j = 0; j < 4; j++)
  29. {
  30. if (!exclude[j] && i != j)
  31. {
  32. if ((guess[i] == right[j]) && !excludeColor[j])
  33. {
  34. inList = true;
  35. grab = j;
  36. }
  37. }
  38. }
  39.  
  40. if (inList)
  41. {
  42. rightColor++;
  43. inList = false;
  44. excludeColor[grab] = true;
  45. }
  46. }
  47. }
  48. if(totalRight == w1 && rightColor == w2){
  49. return true;
  50. }
  51. else{
  52. return false;
  53. }
  54. }
  55. int main(){
  56. int t;
  57. cin>>t;
  58. for(int k=0;k<t;k++){
  59. int a;
  60. cin>>a;
  61. int u;
  62. vector<int>s;
  63. for(int i=0;i<=9999;i++){
  64. s.push_back(i);
  65. }
  66. bool b=1;
  67. int one[4];
  68. int two[4];
  69. for(int i=0;i<a;i++){
  70. cin>>u>>w1>>w2;
  71. two[0] = u/1000;
  72. two[1] = (u/100)%10;
  73. two[2] = (u/10)%10;
  74. two[3] = u%10;
  75. for(int j=0;j<s.size();j++){
  76. one[0]=s[j]/1000;
  77. one[1]=(s[j]/100)%10;
  78. one[2]=(s[j]/10)%10;
  79. one[3]=s[j]%10;
  80. if(!gaveOver(one,two)){
  81. s.erase(s.begin()+j);
  82. }
  83. else{
  84. cout<<s[j]<<endl;
  85. }
  86. }
  87. }
  88. if(s.size() > 1){
  89. cout<<0<<endl;
  90. }
  91. else{
  92. cout<<s.back()<<endl;
  93. }
  94. }
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement