#include <bits/stdc++.h>using namespace std;const int MAXN = 1e5 + 5;int n, x[MAXN], pos[MAXN], order[MAXN];int main() { freopen("guard.in", "r", stdin); freopen("guard.out", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i]; pos[i] = i; } sort(pos + 1, pos + n + 1, [](int a, int b) { return x[a] < x[b]; }); for (int i = 1; i <= n; i++) { order[pos[i]] = i; } for (int i = 1; i <= n; i++) { cout << x[pos[i]] << (i == n ? "\n" : " "); } for (int i = 1; i <= n; i++) { cout << order[i] << (i == n ? "\n" : " "); } for (int i = 1; i <= n; i++) { cout << pos[i] << (i == n ? "\n" : " "); } return 0;}编译错误
时间: 2024-03-22 18:42:52 浏览: 255
vc2019中 源文件<bits/stdc++.h>无法打开
这段代码的问题在于第一行的头文件 `#include<bits/stdc++.h>`,这个头文件不是标准库的一部分,在某些编译器中可能会出现问题。建议使用标准库中需要的头文件,例如 `#include<iostream>` 代替。
此外,缺少空格可能会导致编译错误,建议在每个语句之间都加上空格。修改后的代码如下:
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 5;
int n, x[MAXN], pos[MAXN], order[MAXN];
int main() {
freopen("guard.in", "r", stdin);
freopen("guard.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i];
pos[i] = i;
}
sort(pos + 1, pos + n + 1, [](int a, int b) { return x[a] < x[b]; });
for (int i = 1; i <= n; i++) {
order[pos[i]] = i;
}
for (int i = 1; i <= n; i++) {
cout << x[pos[i]] << (i == n ? "\n" : " ");
}
for (int i = 1; i <= n; i++) {
cout << order[i] << (i == n ? "\n" : " ");
}
for (int i = 1; i <= n; i++) {
cout << pos[i] << (i == n ? "\n" : " ");
}
return 0;
}
```
希望这可以解决您的编译错误问题。
阅读全文