NKCARD - Tráo bài
Tác giả: RR
Ngôn ngữ: C++
#include <iostream>
#include <algorithm>
#define FOR(i,a,b) for(int i=a; i<=b; i++)
using namespace std;
int a[2000111], first, last;
int main() {
int m, k;
scanf("%d %d", &m, &k);
for(int i = 0; i < m; i++)
a[i] = i;
first = 0; last = m-1;
char c;
scanf("%c",&c);
while (c!='.') {
if (c == 'A') {
a[++last] = a[first++];
}
else if (c == 'B') {
a[++last] = a[first+1];
a[first+1] = a[first++];
}
scanf("%c",&c);
}
cout <<a[first+k-1] <<" " <<a[first+k] <<" " <<a[first+k+1];
return 0;
}