zoukankan      html  css  js  c++  java
  • UVa 637

    题目:模拟输出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);
    		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
    ",book[i][1]);
    				else printf("Blank
    ");
    			}
    			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
    ",book[i][3]);
    				else printf("Blank
    ");
    			}
    		}
    	}
    	return 0;
    }
    

  • 相关阅读:
    HTTP 缓存图解
    http协议构成整理
    HTTP2.0
    Event Loop
    斐波那契数列
    归并排序
    快速排序
    史上最全前端资源
    Js 将 Date 转化为指定格式的String
    vue-cli webpack全局引入jquery
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5374922.html
Copyright © 2011-2022 走看看