WOJ1192-Image Conversion

How to convert a gray image into a binary image? Recently, Ginger is doing some research like that. Assume that each pixel in the gray image is represented by one unsigned byte value, which means that gray value is from 0 to 255. For binary image, you know, each pixelray value is either 0 or 1.
Now, give you an Nray image, your mission is to convert it into a Ninary image using the following methods.
1. Each pixel in gray image occupies 1 byte (8 bits), so you can divide a gray image into 8 binary images (B0~B7). The i-th binary image Bi is composed of the i-th bits of each gray value.
2. After that, from 8 binary images, we can get the binary image B by using the logical operator XOR, which is: B = ( ( ( B0 XOR B1 ) XOR B2 ) ...  XOR B7).

输入格式

There are several test cases. Each test case contains N+1 lines.
The first line contains an integer N (1 <= N <= 40), indicates the size of a square gray image.
In the next N lines, each line contains N integers, X (0 <= X <= 255), indicating N pixels in each row of the gray image.

输出格式

For each test case, output an Ninary matrix, representing the final binary image after the conversion. No blank should be printed at the end of each line.

样例输入

2
1 2
3 4

样例输出

1 1
0 1


#include<stdio.h>
#include<string.h>
int er[10];
int main(){
	int n,i,j,m,k,ans;
	while(scanf("%d",&n)==1){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&m);
				k=0;
				memset(er,0,sizeof(er));
				while(m!=0){
					er[k++]=m%2;
					m=m/2;
				}
				ans=er[7]^er[6]^er[5]^er[4]^er[3]^er[2]^er[1]^er[0];
				if(j!=0)
				printf(" ");
				printf("%d",ans); 
			} 
			printf("\n");
		} 
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值