HDU —— 2996 Pagination (模拟) 红太狼 2021-09-26 15:10 157阅读 0赞 题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=2996][http_acm.hdu.edu.cn_showproblem.php_pid_2996] 题目: # Pagination # **Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 119 Accepted Submission(s): 13** Problem Description Google is one of the most popular web search engines in the world. Many chinese like it very much and use it frequently. But recently, China Internet Illegal Information Reporting Centre(CIIRC) strongly criticized Google for "violating China's laws and regulations, contravening social morality and injuring public interest." At the same time, the Great Firewall blocked more and more world famous websites regardless of the complaints from internet users. As worrying about that Google will also be blocked soon, you decide to eatablish your own web search engine named Googolplex((10)^(10^100)) and share it with other ACMers. Unitl now the spider of your Googolplex has crawled so many web pages that the page will be too long to display all the search result in a single page. So it's time to develop the pagination function for Googolplex. Pagination is used for displaying a limited number of results on search engine results pages. As many nicely designed websites, the format of page numbers of your pagination should follow the specification below: ![C270-1004-1.jpg][] 1. As demonstrated in the picture, the format of the page numbers consists of 7 parts. They are, from left to right: first page, left ellipsis, previous mark, middle pages, next mark, right ellipsis, last page. The middle pages part contains the current page that the user is visiting now(it's "8" in the picutre). Please note that some of these parts will be hidden if the current page is some specific values. 2. For the first page part: It always displays "1". If the first page of middle pages part is equal to 1, this part should be hidden. 3. For the left ellipsis part: It always displays "...". If the first page of middle pages part is 2, or the first page part is hidden, this part should be hidden. 4. For the previous mark part: It always displays "<<". If the current page is 1, this part should be hidden. 5. For the middle pages part: It displays M numbers at most. If M is greater than T, the total number of pages, it displays T numbers. The position of the current page C should be M/2+1. So there are M/2 numbers before C and M-(M/2+1) after C. If the numbers before C is less than M/2, the middle pages part will shift to right to ensure there are M numbers displayed in total. If the numbers after C is less than M-(M/2+1), the middle pages part will shift to left to ensure there are M numbers displayed in total. Please refer to the sample for clarification. 6. For the next mark part: It always displays ">>". If the current page is equal to the last page, this part should be hidden. 7. For the right ellipsis part: It always displays "...". If the last page of middle pages part is one less than the total number of pages, or the last page part is hidden, this part should be hidden. 8. For the last page part: It always displays T, the total number of pages. If the last page of middle pages part is equal to T, this part should be hidden. Given T, the total number of pages, M, the number of pages displayed in the middle pages part, and C, the current page that the user is visiting now, please write a program to generate the page numbers of pagination in the required format. Input The input file contains several test cases. Each test case has a line containing three integers T (1 <= T <= 10^9), M (1 <= M <= 50), C (1 <= C <= T). Input is terminated by a line contains "0 0 0". Output For each test case print one line containing the page numbers of the pagination in the requried format. Each part of the pagination should be separated by a single blank. Current page C should be wrapped by "\[\]". Sample Input 10 3 5 8 4 8 0 0 0 Sample Output 1 ... << 4 \[5\] 6 >> ... 10 1 ... << 5 6 7 \[8\] *Hint* For the second test case "8 4 8". The current page is 8, originally the middle pages part should display "6 7 8 9". But there are only 8 pages in total, so the middle pages part should shift one page to left, and display "5 6 7 8". 题目描述: 模拟题,分步模拟即可,设置七个变量分别代表七个部分,初始化为1,代表全部打印,然后按要求置为0,最后在打印即可,需要注意的是,每部分之间会有一个空格为间隔。个人认为,模拟题比较费时间,考逻辑,细心一点就行了。还有,在找不到某个逻辑点时会抓狂的。hhhh 代码: #include <stdio.h> #include<math.h> int main() { int i,j,k; int t,m,n; int a,b,c,d,e,f,g; while(scanf("%d%d%d",&t,&m,&n),t!=0){ a = b = c = d = e = f = g = 1; d = -1; if(m > t) //m>t时显示t页 m = t; if(n == 1) // << c = 0; if(n == t) // >> e = 0; int d1 = t-n>=m-(m/2+1)?0:m-(m/2+1)-(t-n); //需要左移的格数 if(n-1-m/2-d1 <= 0) // 1 a = 0; if(n-1-m/2-d1 == 1 || !a) // L... b = 0; if(n-1-m/2-d1 > 0) // 中间部分 d = n-m/2-d1; else d = 1; int d2 = n-1 >= m/2?0:m/2-(n-1); //需要右移的格数 if(n+(m-(m/2+1))+d2 >= t) // t g = 0; if(!g || t-(n+(m-(m/2+1))+d2) == 1) // R... f = 0; if(a) printf("1 "); if(b) printf("... "); if(c) printf("<< "); if(d){ for(int ijk = d;ijk<n;ijk++) printf("%d ",ijk); printf("[%d]",n); for(int ijk = n+1;ijk<=n+(m-(m/2+1))+d2 && ijk<=t;ijk++) printf(" %d",ijk); } if(e) printf(" >>"); if(f) printf(" ..."); if(g) printf(" %d",t); printf("\n"); } return 0; } [http_acm.hdu.edu.cn_showproblem.php_pid_2996]: http://acm.hdu.edu.cn/showproblem.php?pid=2996 [C270-1004-1.jpg]: /images/20210923/8b75c1eec8a343f5a20fc6d4ec8a6c67.png
还没有评论,来说两句吧...