URAL - 1098 Questions——约瑟夫环

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5;
char s[maxn];
int dp[maxn];
int main() {
    int n = 0;
    while (gets(s + n)) n = strlen(s);
    s[n] = '\0';
    dp[0] = 0;
    for (int i = 1; i <= n; i++) dp[i] = (dp[i-1]+1999)%i;
    if (s[dp[n]] == '?') printf("Yes\n");
    else if (s[dp[n]] == ' ') printf("No\n");
    else printf("No comments\n");
    return 0;
}

    原文作者:约瑟夫环问题
    原文地址: https://blog.csdn.net/hao_zong_yin/article/details/79715290
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞