201703-2 学生排队
- C++
- 总结
本题链接:201703-2 学生排队
本博客给出本题截图:
C++
#include <iostream> #include <algorithm> using namespace std; const int N = 1010; int n, m; int q[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i ++ ) q[i] = i; while (m -- ) { int a, b; cin >> a >> b; int k; for (int i = 1; i <= n; i ++ ) if (q[i] == a) k = i; if (b > 0) { for (int i = 0; i < b; i ++ ) swap(q[k + i], q[k + i + 1]); } else { b = -b; for (int i = 0; i < b; i ++ ) swap(q[k - i], q[k - i - 1]); } } for (int i = 1; i <= n; i ++ ) cout << q[i] << ' '; return 0; }
总结
水题,不解释