201609-2 火车购票
- C++
- 总结
本题链接:201609-2 火车购票
本博客给出本题截图:
C++
#include <iostream> using namespace std; const int N = 110; bool st[N]; int main() { int n; cin >> n; while (n -- ) { int p; cin >> p; bool success = false; for (int i = 1; i <= 100; i += 5) { for (int j = 0; j < 5; j ++ ) { int s = 0; for (int k = j; k < 5; k ++ ) if (!st[i + k]) s ++ ; else break; if (s >= p) { for (int k = 0; k < p; k ++ ) { int t = i + j + k; st[t] = true; cout << t << ' '; } success = true; break; } } if (success) break; } if (!success) { for (int i = 1; i <= 100 && p; i ++ ) if (!st[i]) { p -- ; st[i] = true; cout << i << ' '; } } cout << endl; } return 0; }
总结
水题,不解释