您的位置:首页 > 产品设计 > UI/UE

URAL 1098 Questions <约瑟夫环>

2016-07-06 09:19 465 查看
题意:说一句话,系统进行回复。周期N = 1999,每次遍历一遍字符串(字长不够N,从头循环),找到第N个剔除。找到最后一次剩余的字符。1.若为‘?’,输出Yes2.若为‘   ‘,输出No3.其余情况,输出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;elsereturn (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");elseprintf("No comments\n");return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: