题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1098
Time limit: 1.0 second Memory limit: 64 MB

Problem Description

Holding a collegiate programming contest is a very exhausting work. There is a well-known proverb that one fool can ask so many questions that a hundred clever men will not answer. And during a collegiate programming contest questions are asked by one hundred clever people.

The jury of the Third Urals Collegiate Programming Contest being clever enough has found a simple way to make its work easier. We have invented a simple algorithm that will help us answer ALL your numerous questions! Moreover, this algorithm guarantees that the same questions will have the same answers (this would be hardly possible if we undertake such a task ourselves). According to this algorithm a member of the jury starts to delete characters of the question in the following order:

  1. Starting from the first character he or she counts out N−1 characters (spaces, punctuation marks etc. are considered to be characters too) and deletes the Nth character.
  2. If a string ends the count continues from the beginning of the string.
  3. After deleting a character the count restarts from the character that would be the (N+1)-st in the previous count.
  4. If the last remaining character is a question-mark ("?") then the answer to the question is "Yes". If it is a space then the answer is "No". Any other character will lead to "No comments" answer.

You should help the jury and write a program that will do a hard work of answering your questions tomorrow. The number N is secret and will not be announced even after the end of the contest. Your program should use N = 1999.

For example, taking a string "Is it a good question?" (its length is 22) the characters will be counted in the following way: "Is it a good question?Is it … quest" and "i" will be deleted. Then the count restarts from "on?Is it…" etc., until "s" will be left (thus the answer is "No comments", as usual).

Input

The input is a question, that is any text containing at least one character (end of line is not a character). Each character of the input (excepting the ends of lines) is a part of the question. You should read the question from the input.

The size of the input is not more than 30000.

Output

The answer.

Samples Input

Does the jury of this programming contest use the
algorithm described in this problem to answer my questions?

At least, will anybody READ my question?

This is
UNFAIR!

Samples Output

Yes
No
No comments

Notes

There are no spaces in the sample inputs except for those between words in one line. Thus the first question contains 108 characters, the second contains 40 and the third contains 14.

Problem solving report:

Description: 对输入的字符串,按1999报数,若最后的胜利者为res,根据res对应的字符输出不同的结果。
Problem solving: 约瑟夫问题。

Accepted Code:

/* * @Author: lzyws739307453 * @Language: C++ */
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30005;
char s[MAXN];
int main() {string str = "";int len, res = 0;while (gets(s))str += s;len = str.length();for (int i = 2; i <= len; i++)res = (res + 1999) % i;if (str[res] != '?') {if (str[res] != ' ')printf("No comments\n");else printf("No\n");}else printf("Yes\n");return 0;
}

URAL - Questions(约瑟夫环)相关推荐

  1. 数据结构与算法作业3——约瑟夫环问题(循环链表)

     第二次作业: 习题2 载具杀手与时停高手(约瑟夫环问题) 著名绅士简尚夫有一项特殊的天赋,他可以摧毁任意一辆载具(载具杀手).他的朋友狄傲可以将时间暂停(时停高手).他俩玩一个游戏. 有N辆车,编号 ...

  2. python中约瑟夫环程序_Python实现约瑟夫环问题的方法

    本文实例讲述了Python实现约瑟夫环问题的方法.分享给大家供大家参考,具体如下: 题目:0,1,...,n-1这n个数字排成一个圆圈,从数字0开始每次从这个圆圈里删除第m个数字.求出这个圆圈里剩下的 ...

  3. 约瑟夫环问题的两种解法(详解)

    约瑟夫环问题的两种解法(详解) 题目: Josephus有过的故事:39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓.于是决定了自杀方式,41个人排成一个圆 ...

  4. python约瑟夫环问题给十个学生编号报到3者出列_趣味算法--约瑟夫环问题(示例代码)...

    问题描述 已知n个人(以编号1,2,3,...,n分别表示)围坐在一张圆桌上.指定编号为k的人开始从1报数,数到m的那个人出列:出列那个人的下一位又从1开始报数,数到m的那个人出列:以此规则重复下去, ...

  5. 一文读懂约瑟夫环算法

    2020-05-25 20:13:40 作者 | 扬帆向海 责编 | 王晓曼 出品 | CSDN博客 问题描述 约瑟夫问题(有时也称为约瑟夫斯置换,是一个出现在计算机科学和数学中的问题.在计算机编程的 ...

  6. 面试题小记:1、统计字符串出现的次数,2、约瑟夫环问题

    今天面到了一个比较有意思的笔试题,先记录一下: 1.字符串类似'aaabbccddd',写个方法得出'3a2b2c3d',即统计字符串出现的个数 $arr = str_split('aaabbccdd ...

  7. java实现简单的约瑟夫环问题(二)

    Josephus(约瑟夫)问题的数学方法 前面的内容都是直接来来自于百度百科,后面才是我对这段话的理解 无论是用链表实现还是用数组实现都有一个共同点:要模拟整个游戏过程,不仅程序写起来比较烦,而且时间 ...

  8. 约瑟夫环双向链表c语言实,双向链表与约瑟夫环代码

    双向链表 //注意:该文件操作的链表为带头结点双向链表,头结点数据为-1 #include #include #include #define OK 1 #define ERROR 0 typedef ...

  9. python解决约瑟夫问题_Python实现约瑟夫环问题的方法

    本文实例讲述了Python实现约瑟夫环问题的方法.分享给大家供大家参考,具体如下: 题目:0,1,...,n-1这n个数字排成一个圆圈,从数字0开始每次从这个圆圈里删除第m个数字.求出这个圆圈里剩下的 ...

最新文章

  1. Istio如何使用相同的端口访问网格外服务
  2. Android近场通信---NFC基础(三)
  3. 案例:演示JDBC的使用
  4. linux物理硬盘和sd的对应关系_Linux物理存储结构以及磁盘划分
  5. 《如何搭建小微企业风控模型》第八节 反欺诈策略 节选
  6. 【图像处理】MATLAB:彩色图像处理
  7. 红帽子linux改ip命令,Linux系统下图形界面更改IP地址
  8. obj 转为Json 时间格式自定义
  9. 论文阅读笔记(三)——An Enhanced Hybrid MobileNet
  10. groovy java to swift_groovy数据类型 - Groovy教程
  11. 奈何心是安定心,命总是流浪命
  12. 什么是redux?redux概念及应用
  13. 0、本专栏的预计更新的内容与更新时间表(2022-05-07更新目录排版)
  14. Neural Granger Causality for Nonlinear Time Series
  15. Matlab--基于前馈补偿的PID控制算法及其仿真
  16. DSG-01-3C4-A110-51T油研液压直动式电磁阀
  17. Vivado使用技巧(17):创建IBIS模型
  18. Ubuntu16.04搜索不到wifi列表
  19. 录音文件怎么转文字 手机便签里的录音文字转换方法
  20. Java 9 - JShell介绍

热门文章

  1. k3s 快速入门 - 集群搭建
  2. 重走长征路---OI每周刷题记录---8月16日 2014
  3. 大数据早报:医鸣数据完成近亿元B轮融资 阿里巴巴拟再次发行美元债券(11.15)
  4. 嵌入式Linux获取系统时间
  5. CactiEZ 中文版V10.1安装使用以及139邮箱短信报警设置
  6. spring boot + maven使用profiles进行环境隔离
  7. 鲍尔默:我当CEO时,微软对硬件研发投入真不够
  8. 手机摄影后期处理全面进阶学习教程
  9. 杨澜写给女儿的十四条人生忠告
  10. 15、wxapp - 小程序登录以及全局参数 - 微擎小程序模块应用开发