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:
You can assume that the button "..." is always disabled.
10 5 2 10 1 2
Case #1: (<<)[...](3)(4)[5](6)(7)[...](>>) Case #2: [<<][1](2)(3)[...](>>)
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("\n"); } return 0; }