アットウィキロゴ

Print a Chessboard

10014 : Print a Chessboard




解説

行と列を奇数偶数に分けて出力する。

プログラム

C


C++

+ ...
#include<iostream>
using namespace std;

int main(){
	
	int H,W;
	string first , second;
	
	while(cin >> H >> W, H||W){
	
		for(int i = 0; i < H; i++){
		
			if(i % 2 == 0){
				first = "#";
				second = ".";
			}else{
				first = ".";
				second = "#";
			}
			
			for(int j = 0; j < W; j++){
				if(j % 2 == 0) cout << first;
				else			cout << second;
			}
			
			cout << endl;
		}
		
		cout << endl;
	}

	return 0;
}

Java

最終更新:2012年12月21日 17:53