首页 > 代码库 > UVa 637 - Booklet Printing

UVa 637 - Booklet Printing

题目:模拟输出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