#怪异的洗牌#用队列纯暴力解,比较绕,应该能简化
怪异的洗牌
https://www.nowcoder.com/practice/1801ea11cc9d4732a7f0cb2b0b75c8cf
#include<iostream> #include<string> #include<algorithm> #include<queue> #include<vector> using namespace std; int main() { int n; int k, count; queue<int> card; while (cin >> n) { cin >> k; if (n == 0) break; for (int i = 0; i < n; i++) { card.push(i + 1);//给牌赋初值 } int a[1000]; for (int i = 0; i < k; i++) {//k次操作 cin >> count; for (int j = 0; j < count; j++) {//利用队列实现循环移位 card.push(card.front()); card.pop(); } for (int i = 0; i < n; i++) { a[i] = card.front();//复制队列到a数组 card.pop();//队列清空 } for (int i = 0; i < n / 4; i++) { swap(a[i], a[n / 2 - i - 1]);//前半部分逆序 } for (int i = 0; i < n; i++) { card.push(a[i]);//重新加入队列,进行下一次操作 } } for (int i = 0; i < n; i++) {//输出 cout << card.front() << " "; card.pop();//清空队列 } } }