WOJ1192-Image Conversion

来源:互联网 发布:ubuntu命令行运行软件 编辑:程序博客网 时间:2024/06/10 12:25

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.

样例输入

21 23 4

样例输出

1 10 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;}


原创粉丝点击