zoukankan      html  css  js  c++  java
  • 周赛-KIDx's Pagination 分类: 比赛 2015-08-02 08:23 7人阅读 评论(0) 收藏

    KIDx's Pagination

    Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

    Problem Description

    One Day, KIDx developed a beautiful pagination for ACdream. Now, KIDx wants you to make another one.

    The are n pages in total.
    The current page is cur.
    The max distance to current page you can display is d.

    Here are some rules:

    • The cur page button is disabled.
    • If cur page is the first page, the button "<<" should be disabled.
    • If cur page is the last page, the button ">>" should be disabled.
    • If the button "x" is disabled, print "[x]"; else print "(x)".
    • You should not display the "..." button when there is no hidden page.

    You can assume that the button "..." is always disabled.

    Input

    There are multiple cases.
    Ease case contains three integers n, cur, d.
    1 ≤ n ≤ 100.
    1 ≤ cur ≤ n.
    0 ≤ d ≤ n.

    Output

    For each test case, output one line containing "Case #x: " followed by the result of pagination.

    Sample Input

    10 5 2
    10 1 2

    Sample Output

    Case #1: (<<)[...](3)(4)[5](6)(7)[...](>>)
    Case #2: [<<][1](2)(3)[...](>>)

    Hint

    Case 1: 

    Case 2: 

    周赛的一道模拟

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <map>
    #include <list>
    #include <algorithm>
    #define LL long long
    #define RR freopen("output.txt","r",stdin)
    #define WW freopen("input.txt","w",stdout)
    
    using namespace std;
    bool vis[120];
    int main()
    {
        int n,cur,d;
        int w=1;
        while(~scanf("%d %d %d",&n,&cur,&d))
        {
            memset(vis,false,sizeof(vis));
            for(int i=1; i<=n; i++)
            {
                if((cur-i<=d&&cur-i>=0)||(i-cur<=d&&i-cur>=0))
                {
                    vis[i]=true;
                }
            }
            printf("Case #%d: ",w++);
            if(cur==1)
            {
                printf("[<<]");
            }
            else
            {
                printf("(<<)");
            }
            for(int i=1; i<=n; i++)
            {
                if(i==1)
                {
                    if(vis[i])
                    {
                        if(cur==i)
                            printf("[%d]",i);
                        else
                        {
                            printf("(%d)",i);
                        }
                    }
                    else
                    {
                        printf("[...]");
                    }
                }
                else if(i==n)
                {
                    if(vis[n])
                    {
                        if(cur==n)
                            printf("[%d]",i);
                        else
                        {
                            printf("(%d)",i);
    
                        }
                    }
                    else
                    {
                        printf("[...]");
                    }
                }
                else if(vis[i])
                {
                    if(cur==i)
                    printf("[%d]",i);
                    else
                    {
                        printf("(%d)",i);
                    }
    
                }
            }
            if(cur==n)
            {
                printf("[>>]");
            }
            else
            {
                printf("(>>)");
    
            }
            printf("
    ");
        }
    
    
        return 0;
    }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Effective C# 学习笔记(三十五) 了解PLINQ如何实现并行算法
    Effective C# 学习笔记(三十八)理解Dynamic的得与失
    转单例的分析
    获取系统当前音量 和 监听系统音量 ios
    (转) iphone开发资源汇总
    xcode show line numbers
    为了编程方便的效率宏定义的一些代码
    ios6下cocos2d & ipad 调用摄像头报错问题 (在竖屏情况下调用Camera 会导致转屏)
    转KVC
    不记住的
  • 原文地址:https://www.cnblogs.com/juechen/p/4721947.html
Copyright © 2011-2022 走看看