标签:
题目大意:
#include<iostream>
#include<cstdio>
using namespace std;
int main () {
int n, k, m;//n,k逆时针 m顺时针
while (scanf("%d%d%d", &n, &k, &m) == 3 && (n || k || m)) {
int num[20] = {0};
for (int i = 0; i != n; ++i) {
num[i] = i + 1;
}
int pop(0);
int idx1(0), idx2(n - 1);
while (pop != n) {
if (pop) printf(",");
for (int i = idx1, cnt = 0; cnt != k; ++i) {
if (num[i]) {
if (++cnt == k) idx1 = i;
}
if (i == n - 1) i = -1;
}
for (int i = idx2, cnt = 0; cnt != m; --i) {
if (num[i]) {
if (++cnt == m) idx2 = i;
}
if (!i) i = n;
}
if (idx1 == idx2) {
++pop;
printf("%3d", num[idx1]);
num[idx1] = 0;
}else {
pop += 2;
printf("%3d%3d", num[idx1], num[idx2]);
num[idx1] = 0;
num[idx2] = 0;
}
}
printf("\n");
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4567459.html