#include "combo.h"
using namespace std;
string guess_sequence(int n) {
string ans, t; int i, j, k; char s[4] = {'A', 'B', 'X', 'Y'};
t.push_back('A'); t.push_back('B');
if(press(t)){
t.clear(); t.push_back('A');
(press(t))? ans.push_back('A'): ans.push_back('B');
} else{
t.clear(); t.push_back('X');
(press(t))? ans.push_back('X'): ans.push_back('Y');
}
for( j = 0; ; j++) if(s[j] == ans[0]) break;
for( i = 1; i < n-1; i++){
t.clear();
t += ans; t.push_back(s[(j+1) % 4]);
t += ans; t.push_back(s[(j+2) % 4]); t.push_back(s[(j+1) % 4]);
t += ans; t.push_back(s[(j+2) % 4]); t.push_back(s[(j+2) % 4]);
t += ans; t.push_back(s[(j+2) % 4]); t.push_back(s[(j+3) % 4]);
k = press(t);
if(k == ans.size()) ans.push_back(s[(j+3) % 4]);
else if(k == ans.size()+1) ans.push_back(s[(j+1) % 4]);
else ans.push_back(s[(j+2) % 4]);
}
if(n > 1){
t.clear();
t += ans; t.push_back(s[(j+1) % 4]);
t += ans; t.push_back(s[(j+2) % 4]);
if(press(t) != ans.size()){
t.clear();
t += ans; t.push_back(s[(j+1) % 4]);
(press(t) != ans.size())? ans.push_back(s[(j+1) % 4]): ans.push_back(s[(j+2) % 4]);
} else ans.push_back(s[(j+3) % 4]);
} return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |