zoukankan      html  css  js  c++  java
  • POJ 2359 Questions

    Questions
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 1096   Accepted: 394

    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 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:
    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 file 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.
    The size of the input file is not more than 30000.

    Output

    The answer.

    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
     1 /* 
     2    功能Function Description:     POJ-2359
     3    开发环境Environment:          DEV C++ 4.9.9.1
     4    技术特点Technique:
     5    版本Version:
     6    作者Author:                   可笑痴狂
     7    日期Date:                      20120801
     8    备注Notes:
     9    注意:
    10         本题就一组测试数据,是遇到ctrl+z后按回车结束的。
    11         下边是三个AC代码
    12 */
    13 /*
    14 代码一:
    15 #include<iostream>  
    16 #include<string>  
    17 using namespace std;  
    18 #define N 1999    
    19 int main()  
    20 {   
    21     string s;   
    22     char ch[30003];   
    23     int len,i,cnt=0;     
    24     while(gets(ch))    
    25         s+=ch;      //string的连接,与字符数组的strcat作用相同,也是将原来的string结束符去掉再连接上后边的字符串
    26     len=s.size();   
    27     for(i=2;i<=len;i++)      //约瑟夫环数学解法
    28         cnt=(cnt+N)%i;     
    29     if(s[cnt]=='?') 
    30         printf("Yes\n");    
    31     else if(s[cnt]==' ') 
    32         printf("No\n");   
    33     else 
    34         printf("No comments\n");   
    35     return 0;  
    36 }
    37 
    38 
    39 /*
    40 代码二:
    41 #include <cstdio>
    42 #include <cstring>
    43 #include <iostream>
    44 #include <string>
    45 using namespace std;
    46 string s;
    47 int N = 1999;
    48 char c;
    49 int main() 
    50 {
    51     while((c = getchar()) != EOF) 
    52     {
    53         if(c == '\n') continue;
    54         s += c;
    55     }
    56     int len =s.length();
    57     int cnt = 0;
    58     for(int i=2;i<=len;i++)
    59         cnt=(cnt+N)%i;
    60     if(s[cnt] == '?') 
    61         printf("Yes\n");
    62     else if(s[cnt] == ' ') 
    63         printf("No\n");
    64     else 
    65         printf("No comments\n");
    66     return 0;
    67 }
    68 */
    69 
    70 
    71 //代码三:
    72 #include<iostream>  
    73 #include<string>  
    74 using namespace std;  
    75 #define N 1999    
    76 int main()  
    77 {   
    78     char ch[30003],s[30003];
    79     int len,i,cnt=0; 
    80     s[0]='\0';
    81     while(gets(ch))    
    82         strcat(s,ch);      //连接
    83     len=strlen(s);   
    84     for(i=2;i<=len;i++)      //约瑟夫环数学解法
    85         cnt=(cnt+N)%i;     
    86     if(s[cnt]=='?') 
    87         printf("Yes\n");    
    88     else if(s[cnt]==' ') 
    89         printf("No\n");   
    90     else 
    91         printf("No comments\n");   
    92     return 0;  
    93 }
    功不成,身已退
  • 相关阅读:
    JSON.stringify深拷贝的缺点
    Vue生命周期和详细的执行过程
    CSS中width:100%和width:auto的区别
    react中的setState的使用和深入理解
    一文看懂Chrome浏览器运行机制
    闭包和垃圾回收机制
    linux 下的文件下载和上传
    mvn install本地安装jar到指定仓库
    内网maven依赖仓库jar报错解决
    hbase源码编译调试
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2624589.html
Copyright © 2011-2022 走看看