码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 637 - Booklet Printing

时间:2014-10-15 01:20:19      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:blog   io   for   2014   on   log   amp   size   as   

题目:模拟输出n页书的装订打印状态。

分析:模拟。页数为(n+3)/ 4,只有n不超过半篇时会输出半篇。

说明:好多以前做过的题目(⊙_⊙)。

#include <cstdlib>
#include <cstring>
#include <cstdio>

int book[30][4];

int main()
{
	int n;
	while (~scanf("%d",&n) && n) {
		int page = (n+3)/4;
		memset(book ,0 ,sizeof(book));
		int count = 1;
		for (int i = 1 ; i <= page ; ++ i) {
			book[i][1] = count ++;
			if (count > n) break;
			book[i][2] = count ++;
			if (count > n) break;
		}
		if (count <= n)
		for (int i = page ; i >= 1 ; -- i) {
			book[i][3] = count ++;
			if (count > n) break;
			book[i][0] = count ++;
			if (count > n) break;
		}
		
		printf("Printing order for %d pages:\n",n);
		for (int i = 1 ; i <= page ; ++ i) {
			if (book[i][0] || book[i][1]) {
				printf("Sheet %d, front: ",i);
				if (book[i][0]) printf("%d, ",book[i][0]);
				else printf("Blank, ");
				if (book[i][1]) printf("%d\n",book[i][1]);
				else printf("Blank\n");
			}
			if (book[i][2] || book[i][3]) {
				printf("Sheet %d, back : ",i);
				if (book[i][2]) printf("%d, ",book[i][2]);
				else printf("Blank, ");
				if (book[i][3]) printf("%d\n",book[i][3]);
				else printf("Blank\n");
			}
		}
	}
	return 0;
}

UVa 637 - Booklet Printing

标签:blog   io   for   2014   on   log   amp   size   as   

原文地址:http://blog.csdn.net/mobius_strip/article/details/40088277

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!