Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int w1,w2;
- bool gaveOver(int guess[], int right[]){
- int totalRight = 0;
- int rightColor = 0;
- int grab;
- bool exclude[4];
- bool excludeColor[4];
- bool inList = false;
- for (int i = 0; i < 4; i++){
- exclude[i] = false;
- excludeColor[i] = false;
- }
- for (int i = 0; i < 4; i++)
- {
- if (guess[i] == right[i])
- {
- totalRight++;
- exclude[i] = true;
- }
- }
- for (int i = 0; i < 4; i++)
- {
- if (!exclude[i])
- {
- for (int j = 0; j < 4; j++)
- {
- if (!exclude[j] && i != j)
- {
- if ((guess[i] == right[j]) && !excludeColor[j])
- {
- inList = true;
- grab = j;
- }
- }
- }
- if (inList)
- {
- rightColor++;
- inList = false;
- excludeColor[grab] = true;
- }
- }
- }
- if(totalRight == w1 && rightColor == w2){
- return true;
- }
- else{
- return false;
- }
- }
- int main(){
- int t;
- cin>>t;
- for(int k=0;k<t;k++){
- int a;
- cin>>a;
- int u;
- vector<int>s;
- for(int i=0;i<=9999;i++){
- s.push_back(i);
- }
- bool b=1;
- int one[4];
- int two[4];
- for(int i=0;i<a;i++){
- cin>>u>>w1>>w2;
- two[0] = u/1000;
- two[1] = (u/100)%10;
- two[2] = (u/10)%10;
- two[3] = u%10;
- for(int j=0;j<s.size();j++){
- one[0]=s[j]/1000;
- one[1]=(s[j]/100)%10;
- one[2]=(s[j]/10)%10;
- one[3]=s[j]%10;
- if(!gaveOver(one,two)){
- s.erase(s.begin()+j);
- }
- else{
- cout<<s[j]<<endl;
- }
- }
- }
- if(s.size() > 1){
- cout<<0<<endl;
- }
- else{
- cout<<s.back()<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement