模拟 ACdream 1196 KIDx's Pagination

 

题目传送门

 1 /*  2  简单模拟;考虑边界的情况输出的是不一样的,还有思维好,代码能短很多  3 */  4 #include <cstdio>  5 #include <iostream>  6 #include <algorithm>  7 #include <string>  8 #include <cstring>  9 #include <map> 10 #include <vector> 11 using namespace std; 12 13 const int MAXN = 1e4 + 10; 14 const int INF = 0x3f3f3f3f; 15 16 int main(void) //ACdream 1196 KIDx's Pagination 17 { 18 //freopen ("A.in", "r", stdin); 19 20 int n, cur, d; 21 int a[110]; 22 int cas = 0; 23 while (scanf ("%d%d%d", &n, &cur, &d) == 3) 24  { 25 printf ("Case #%d: ", ++cas); 26 if (cur == 1) printf ("[<<]"); 27 else printf ("(<<)"); 28 29 if (cur - d > 1) printf ("[...]"); 30 for (int i=max(cur-d, 1); i<cur; ++i) printf ("(%d)", i); 31 printf ("[%d]", cur); 32 for (int i=cur+1; i<=min(cur+d, n); ++i) printf ("(%d)", i); 33 if (cur + d < n) printf ("[...]"); 34 35 if (cur == n) printf ("[>>]"); 36 else printf ("(>>)"); 37 puts (""); 38  } 39 40 return 0; 41 } 42 43 /* 44 Case #1: (<<)[...](3)(4)[5](6)(7)[...](>>) 45 Case #2: [<<][1](2)(3)[...](>>) 46 */

 

你可能感兴趣的:(pagination)