URAL 1098 Questions <约瑟夫环>

题意:说一句话,系统进行回复。周期N = 1999,每次遍历一遍字符串(字长不够N,从头循环),找到第N个剔除。找到最后一次剩余的字符。

1.若为‘?’,输出Yes

2.若为‘   ‘,输出No

3.其余情况,输出No comments

样例:

inputoutput
Does the jury of this programming contest use the
algorithm described in this problem to answer my questions?
Yes
At least, will anybody READ my question?
No
This is
UNFAIR!
No comments
 
#include<iostream>
#include<cstdio>
using namespace std;

char str[30003];
int fun(int m,int k,int i)//以k为周期,m长度,第i次,输出的编号(0,1,2,...,m-1)
{
    if(i==1)
        return (m+k-1)%m;
    else
        return (fun(m-1,k,i-1)+k)%m;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int len=0;
    while(scanf("%c",&str[0])!=EOF)
    {
        if(str[0]>=' ')
        {
            str[++len]=str[0];//printf(" c = %c\n",str[0]);
        }
    }
    int k=fun(len,1999,len) +1;
    //printf("str[%d] =  %c\n",k,str[k]);
    if (str[k]=='?')
        printf("Yes\n");
    else if (str[k]==' ')
        printf("No\n");
    else
        printf("No comments\n");
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值