POJ 1313 Booklet Printing
問題
略
やりかた
見開きのページ番号の和はどの見開きであっても一定(ページ数以上の最小の4の倍数+1になる)になるので片一方の番号がわかれば見開きのもう片方の番号は自動的に決まる。コード上では見開き上の若番の番号から老番のページ番号を求めて、それが与えられたページ数以上になる場合には老番の位置に"Blank"を出力しておけばいい。ただ若番もページ数以上になる場合があるのでその時は表示しないようにする。
以下ソース。
int main(int argc, char **argv){ int n; while(cin >> n, n){ int sheet = (n + 3) / 4; cout << "Printing order for " << n << " pages:" << endl; for(int i = 1; i <= sheet; i++){ int fr = 2 * i - 1; int bl = 2 * i; int fl = sheet * 4 + 1 - fr; int br = sheet * 4 + 1 - bl; cout << "Sheet " << i << ", front: "; if(fl > n) cout << "Blank, "; else cout << fl << ", "; cout << fr << endl; if(bl <= n){ cout << "Sheet " << i << ", back : "; cout << bl << ", "; if(br > n) cout << "Blank"; else cout << br; cout << endl; } } } return 0; }
Get up! 明日のSUPER ST@R!