p 3750
要求每次都输出的约瑟夫环
#include <iostream> #include <cstdio> #include <cstring> using namespace std; char s[100][30]; int flag[100]; int n, w, S, num, k; int main() { while(scanf("%d", &n)!=EOF) { for(int i = 1;i <= n;i++) { scanf("%s", s[i]); flag[i] = 1; } scanf("%d,%d", &w, &S); for(int i = 1;i <= n;i++) { num = 0; while(num < S) { if(flag[w]) { num++; } k = w; w++; if(w > n) w = 1; } printf("%s\n", s[k]); flag[k] = 0; } } return 0; }