Pagini recente » Cod sursa (job #2208775) | Cod sursa (job #1973742) | Cod sursa (job #2212605) | Cod sursa (job #2725378) | Cod sursa (job #2750728)
#include <fstream>
std::ifstream fin ("schi.in");
std::ofstream fout ("schi.out");
int const nmax = 30000;
struct MyStruct {
int val;
int fol; // following
} v[nmax + 5];
int main() {
int n;
fin >> n;
int used = 0;
v[0].val = -1;
v[0].fol = -1;
for (int i = 1; i <= n; i++) {
bool checked = false;
int new_pos;
fin >> new_pos;
int ind = 0, cnt = 0;
while (v[ind].fol != -1) {
if (cnt + 1 == new_pos) {
int afterind = v[ind].fol;
v[ind].fol = ++used;
v[used].val = i;
v[used].fol = afterind;
checked = true;
break;
}
ind = v[ind].fol;
cnt++;
}
if (!checked) {
v[ind].fol = ++used;
v[used].val = i;
v[used].fol = -1;
}
}
int ind = 0;
while (ind != -1) {
if (ind)
fout << v[ind].val << "\n";
ind = v[ind].fol;
}
return 0;
}