POJ 2359 Questions
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1228 | Accepted: 449 |
Description
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 would undertook such a task ourselves). According to this algorithm a member of the jury starts to delete characters of the question in the following order:
- 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.
- If a string ends the count continues from the beginning of the string.
- After deleting a character the count restarts from the character that would be the (N+1)-st in the previous count.
- 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 size of the input file is not more than 30000.
Output
Sample Input
Sample input #1
Does the jury of this programming contest use the
algorithm described in this problem to answer my questions? Sample input #2
At least, will anybody READ my question? Sample input #3
This is
UNFAIR!
Sample Output
Sample output #1
Yes Sample output #2
No Sample output #3
No comments
解题方法:约瑟夫问题,直接套用递推公式。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; char temp[]; int main()
{
string str;
int n = ;
int ans = ;
while(gets(temp))
{
str += temp;
}
int nLen = str.length();
for (int i = ; i <= nLen; i++)
{
ans = (ans + n) % i;
}
if (str[ans] == '?')
{
printf("Yes\n");
}
else
{
if (str[ans] == ' ')
{
printf("No\n");
}
else
{
printf("No comments\n");
}
}
return ;
}
最新文章
- java中的单例模式(懒汉式+饿汉式)
- HDU5128 细心、细心、细心
- Javascript设计模式之创建对象的灵活性
- Hadoop2.0重启脚本
- windows身份验证模式和SQL server身份验证模式 有什么不同
- JSON.parse这个是啥?
- Bitwise And Queries
- C语言之阶乘
- Java泛型方法与泛型类的使用------------(五)
- springMVC 复选框带有选择项记忆功能的处理
- django模板常用过滤器—add、cut、date
- 迭代器和增强for
- JavaScript Drag处理
- PowerBuilder编程新思维4:钩挂(界面美化与DirectUI)
- create-react-app脚手架使用
- Ubuntu中基于QT的系统网线连接状态的实时监视
- vi文字处理器
- Sequelize-nodejs-9-Scopes
- bss段和.data的是是非非
- springmvc拦截器的配置、使用
热门文章
- Java设计模式开篇
- ES-什么是elasticsearch
- error c2243:";类型转换"; 转换存在,但无法访问
- mysql命令行执行时不输出列名(字段名)
- sublime快捷键mark
- nmon安装和使用介绍
- X11/extensions/XShm.h: No such file or directory
- org.thymeleaf.exceptions.TemplateInputException: Error resolving template ";/home/index2";, template might not exist or might not be accessible by any of the configured Template Resolvers
- Gym 100342E 	Minima (暴力,单调队列)
- win10文件共享的实现