#include #include #include #include #include #include using namespace std; //vectorasked; paircalc(string SQ,string SA) { int idx[10]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; idx[SA[0]-'0']=0; idx[SA[1]-'0']=1; idx[SA[2]-'0']=2; idx[SA[3]-'0']=3; int H=0,B=0; for(int i=0;i<4;i++) { int j=idx[SQ[i]-'0']; if(j==i)H++; else if(j>=0)B++; } /* for(int i=0;i<4;i++) { if(SQ[i]==SA[i])H++; for(int j=0;j<4;j++)if(i!=j&&SQ[i]==SA[j])B++; } */ return make_pair(H,B); } string ans; vectorSQs; void dfs(vectorSAs,int t) { if(SAs.size()==1) { //output cout<<"! "<>a;if(a==-1)exit(0); return; } assert(t<6); int mx_min=1e9; string SSQ; for(string SQ:SQs) { map,vector >mp; int mx=0; for(string SA:SAs) { auto p=calc(SQ,SA); mp[p].push_back(SA); mx=max(mx,(int)mp[p].size()); } if(mx_min>mx) { mx_min=mx; SSQ=SQ; } } //asked.push_back(SSQ); cout<<"? "<ret; cin>>ret.first>>ret.second; //ret=calc(SSQ,ans); vectornSAs; for(string SA:SAs)if(calc(SSQ,SA)==ret)nSAs.push_back(SA); dfs(nSAs,t+1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if(false) { for(int v=0;v<=9999;v++) { string t=""; t+=v/1000+'0'; t+=v/100%10+'0'; t+=v/10%10+'0'; t+=v%10+'0'; string st=t; sort(st.begin(),st.end()); if(st[0]!=st[1]&&st[1]!=st[2]&&st[2]!=st[3])SQs.push_back(t); } assert(SQs.size()==10*9*8*7); } SQs={"0123","0124","0125","0126","0128","0145","0148","0167","0168","0178","0214","0415","0456","0467","0567","0617","0718","2567","4156","4325",}; vectorSAs; { for(int M=1;M<=12;M++) { int L=M==2?29:L==4||L==6||L==9||L==11?30:31; for(int D=1;D<=L;D++) { string t=""; t+=M/10+'0'; t+=M%10+'0'; t+=D/10+'0'; t+=D%10+'0'; string st=t; sort(st.begin(),st.end()); if(st[0]!=st[1]&&st[1]!=st[2]&&st[2]!=st[3])SAs.push_back(t); } } } int T;cin>>T; for(;T--;) { //cin>>ans; dfs(SAs,0); } /* sort(asked.begin(),asked.end()); asked.erase(unique(asked.begin(),asked.end()),asked.end()); cout<<"{"; for(string t:asked)cout<<'"'<