zoukankan      html  css  js  c++  java
  • ZOJ Problem Set 2965 Accurately Say "CocaCola"!

    ZOJ Problem Set - 2965
    Accurately Say "CocaCola"!

    Time Limit: 1 Second      Memory Limit: 32768 KB

    In a party held by CocaCola company, several students stand in a circle and play a game.

    One of them is selected as the first, and should say the number 1. Then they continue to count number from 1 one by one (clockwise). The game is interesting in that, once someone counts a number which is a multiple of 7 (e.g. 7, 14, 28, ...) or contains the digit '7' (e.g. 7, 17, 27, ...), he shall say "CocaCola" instead of the number itself.

    For example, 4 students play this game. At some time, the first one says 25, then the second should say 26. The third should say "CocaCola" because 27 contains the digit '7'. The fourth one should say "CocaCola" too, because 28 is a multiple of 7. Then the first one says 29, and the game goes on. When someone makes a mistake, the game ends.

    During a game, you may hear a consecutive of p "CocaCola"s. So what is the minimum number that can make this situation happen?

    For example p = 2, that means there are a consecutive of 2 "CocaCola"s. This situation happens in 27-28 as stated above. 27 is then the minimum number to make this situation happen.

    Input

    Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 100) which is the number of test cases. And it will be followed by Tconsecutive test cases.

    There is only one line for each case. The line contains only one integer p (1 <= p <= 99).

    Output

    Results should be directed to standard output. The output of each test case should be a single integer in one line, which is the minimum possible number for the first of thep "CocaCola"s stands for.

    Sample Input

    2
    2
    3
    

    Sample Output

    27
    70
    

    Author: HANG, Hang
    Source: The 5th Zhejiang Provincial Collegiate Programming Contest
    SOURCE CODE:
    #include<iostream>
    #include
    <string>
    #include
    <map>
    using namespace std;

    void initialCocaCola(map<int, int>& cocacola)
    {
    cocacola[
    1] = 7;
    cocacola[
    2] = 27;
    cocacola[
    3] = 70;
    cocacola[
    4] = 70;
    cocacola[
    5] = 70;
    cocacola[
    6] = 70;
    cocacola[
    7] = 70;
    cocacola[
    8] = 70;
    cocacola[
    9] = 70;
    cocacola[
    10] = 70;
    cocacola[
    11] = 270;

    for(int i = 12; i < 100; i++)
    {
    cocacola[i]
    = 700;
    }
    }

    int main()
    {
    map
    <int, int> CocaCola;
    initialCocaCola(CocaCola);

    int cases;cin>>cases;
    int consecutive;
    while(cases--)
    {
    cin
    >>consecutive;
    cout
    <<CocaCola[consecutive]<<endl;
    }
    return 0;
    }
    OR:
    #include<iostream>
    using namespace std;

    int main()
    {
    int cases;cin>>cases;
    int consecutive;
    while(cases--)
    {

    cin
    >>consecutive;
    int result = 7;
    if(consecutive == 1)
    {
    result
    = 7;
    }
    else if(consecutive == 2)
    {
    result
    = 27;
    }
    else if( consecutive > 2 && consecutive <= 10)
    {
    result
    = 70;
    }
    else if( consecutive == 11)
    {
    result
    = 270;
    }
    else
    {
    result
    = 700;
    }
    cout
    <<result<<endl;
    }
    return 0;
    }

  • 相关阅读:
    与IBM的Lin Sun关于Istio 1.0和微服务的问答
    与IBM的Lin Sun关于Istio 1.0和微服务的问答
    与IBM的Lin Sun关于Istio 1.0和微服务的问答
    各种排序算法汇总
    更改一个链接的文本、URL 以及 target
    使用javascript中读取Xml文件做成的一个二级联动菜单
    HTML DOM 实例
    HTML DOM
    js中邦定事件与解绑支持匿名函数
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/malloc/p/2096507.html
Copyright © 2011-2022 走看看