SDUT 1104 Image Transformation

题目描述

The image stored on a computer can be represented as a matrix of pixels. In the RGB (Red-Green-Blue) color system, a pixel can be described as a triplex integer numbers. That is, the color of a pixel is in the format "r g b" where r, g and b are integers ranging from 0 to 255(inclusive) which represent the Red, Green and Blue level of that pixel.

Sometimes however, we may need a gray picture instead of a colorful one. One of the simplest way to transform a RGB picture into gray: for each pixel, we set the Red, Green and Blue level to a same value which is usually the average of the Red, Green and Blue level of that pixel (that is (r + g + b)/3, here we assume that the sum of r, g and b is always dividable by 3).

You decide to write a program to test the effectiveness of this method.

输入

The input contains multiple test cases!

Each test case begins with two integer numbers N and M (1 <= N, M <= 100) meaning the height and width of the picture, then three N * M matrices follow; respectively represent the Red, Green and Blue level of each pixel.

A line with N = 0 and M = 0 signals the end of the input, which should not be proceed.

输出

For each test case, output "Case #:" first. "#" is the number of the case, which starts from 1. Then output a matrix of N * M integers which describe the gray levels of the pixels in the resultant grayed picture. There should be N lines with M integers separated by a comma.

示例输入

2 2
1 4
6 9
2 5
7 10
3 6
8 11
2 3
0 1 2
3 4 2
0 1 2
3 4 3
0 1 2
3 4 4
0 0

示例输出

Case 1:
2,5
7,10
Case 2:
0,1,2
3,4,3

  1. #include <stdio.h>  
  2. int main()  
  3. {  
  4.     int a[101][101],b[101][101],c[101][101],d[101][101];  
  5.     int n,m,j,i,k,l,h;  
  6.     int x=0,y,p,q;  
  7.     while(scanf("%d %d",&n,&m)!=EOF&&n||m)  
  8.     {  
  9.         x++;  
  10.         for(i=0;i<n;i++)  
  11.         {  
  12.             for(j=0;j<m;j++)  
  13.             {  
  14.                 scanf("%d",&a[i][j]);  
  15.             }  
  16.         }  
  17.         for(i=0;i<n;i++)  
  18.         {  
  19.             for(j=0;j<m;j++)  
  20.             {  
  21.                 scanf("%d",&b[i][j]);  
  22.             }  
  23.         }  
  24.         for(i=0;i<n;i++)  
  25.         {  
  26.             for(j=0;j<m;j++)  
  27.             {  
  28.                 scanf("%d",&c[i][j]);  
  29.             }  
  30.         }  
  31.         for(i=0;i<n;i++)  
  32.         {  
  33.             for(j=0;j<m;j++)  
  34.             {  
  35.                 d[i][j]=(a[i][j]+b[i][j]+c[i][j])/3;  
  36.             }  
  37.         }  
  38.         printf("Case %d:\n",x);  
  39.         for(i=0;i<n;i++)  
  40.         {  
  41.             for(j=0;j<m;j++)  
  42.             {  
  43.                 if(j==0)  
  44.                 printf("%d",d[i][j]);  
  45.                 else  
  46.                     printf(",%d",d[i][j]);  
  47.             }  
  48.             printf("\n");  
  49.         }  
  50.     }  
  51.     return 0;  
  52. }  
  53.    
  54.   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值