您的位置:首页 > 其它

ACdream 1196 KIDx's Pagination(模拟)

2014-09-07 10:41 218 查看


KIDx's Pagination

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

SubmitStatisticNext
Problem


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

KIDx

SubmitStatistic

感觉就是模拟电子书的页面显示效果

自己的代码写的比较挫...

代码如下:

#include <bits/stdc++.h>
using namespace std;

int main(void) {
int n, cur, d, t;
t = 1;
while(scanf("%d%d%d", &n, &cur, &d) != EOF) {
printf("Case #%d: ", t++);

if(cur == 1 && cur == n) {
printf("[<<][1][>>]\n");
continue;
}

if(cur == 1) {
printf("[<<][1]");
if(cur+d < n) {
for(int i=2; i<=cur+d; ++i) {
printf("(%d)", i);
}
printf("[...](>>)\n");
}
else if(cur+d >= n) {
for(int i=2; i<=n; ++i) {
printf("(%d)", i);
}
printf("(>>)\n");
}

}

else if(cur == n) {
if(cur-d > 1) {
printf("(<<)[...]");
for(int i=cur-d; i<n; ++i) {
printf("(%d)", i);
}
}
else if(cur-d <= 1){
printf("(<<)");
for(int i=1; i<n; ++i) {
printf("(%d)", i);
}
}
printf("[%d][>>]\n", n);
}

else if(cur-d > 1) {
printf("(<<)[...]");
if(cur+d < n) {
for(int i=cur-d; i<=cur+d; ++i) {
if(i == cur) {
printf("[%d]", i);
} else printf("(%d)", i);
}
printf("[...](>>)\n");
}
else if(cur+d >= n) {
for(int i=cur-d; i<=n; ++i) {
if(i == cur)
printf("[%d]", i);
else printf("(%d)", i);
}
printf("(>>)\n");
}
}

else if(cur-d <= 1){
printf("(<<)");
if(cur+d < n) {
for(int i=1; i<=cur+d; ++i)
if(i == cur)
printf("[%d]", cur);
else
printf("(%d)", i);
printf("[...](>>)\n");
}
else if(cur+d >= n) {
for(int i=1; i<=n; ++i) {
if(i == cur) {
printf("[%d]", i);
}
else printf("(%d)", i);
}
printf("(>>)\n");
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: