KIDx's Pagination

本文介绍了一个简单的分页器模拟题目,通过给定的总页数、当前页及显示范围来生成页面导航栏。代码示例使用 C 语言实现,展示了如何根据规则动态生成分页按钮。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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: 

Source
KIDx
Manager
///这是一道简单的模拟题,可我>_<||
#include<stdio.h>
#include<string.h>
#include<math.h>

int main()
{
    int n, cur, d, num=0;
    while(~scanf("%d%d%d", &n, &cur, &d))
    {
        num++;
        printf("Case #%d: ", num);
        if(cur==1)
            printf("[<<]");
        else
            printf("(<<)");
        if(cur-d>1)
            printf("[...]");
        for(int i=1;i<=n;i++)
        {
            if(i==cur)
                printf("[%d]", cur);
            else if(fabs(cur-i)<=d)
                printf("(%d)", i);
        }
        if(cur+d<n)
            printf("[...]");
        if(cur==n)
            printf("[>>]");
        else
            printf("(>>)");
        puts("");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值