Pagini recente » Cod sursa (job #1154049) | Cod sursa (job #218318) | Cod sursa (job #2868242) | Cod sursa (job #3277712) | Cod sursa (job #2862140)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e4;
int tg[nmax+5];
int n;
string fin;
int poz;
bool eval() {
bool ok = true;
while(ok and poz<n) {
ok = false;
if(fin[poz]>='1' and fin[poz]<='3') {
ok = true;
}
else if(fin[poz]=='A') {
fin[poz] = tg[poz] + '0';
ok = true;
}
else if(fin[poz]=='B') {
if(tg[poz]==2) {
fin.replace(poz,1,"2B");
ok = true;
}
else if(tg[poz]==1) {
fin.replace(poz,1,"1A3AC");
ok = true;
}
}
else if(fin[poz]=='C') {
if(tg[poz]==2) {
fin[poz] = '2';
ok = true;
}
else if(tg[poz]==3) {
fin.replace(poz,1,"3BC");
ok = true;
}
else if(tg[poz]==1) {
fin.replace(poz,1,"12A");
ok = true;
}
}
poz++;
}
if(fin.size()>n) return false;
for(int i=0; i<n; i++)
if(tg[i]+'0'!=fin[i]) return false;
return true;
}
int main() {
ifstream f("perle.in");
ofstream g("perle.out");
int q; f >> q;
for(int cas=1; cas<=q; cas++) {
f >> n;
for(int i=0; i<n; i++) f >> tg[i];
fin = "";
if(n==1) fin = fin + "A";
else if(tg[0]==1 and n==3) fin = fin + "C";
else if(tg[0]==1) fin = fin + "B";
else if(tg[0]==2) fin = fin + "B";
else if(tg[0]==3) fin = fin + "C";
poz = 0; g << eval() << "\n";
}
return 0;
}