c++
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
// 持續讀取輸入,直到沒有資料
while(cin>>n){
// sumY 用來累加所有像素的 Y 值
// x、y、z 為轉換後的 XYZ 色彩空間數值
// avg 為最後的平均 Y 值
double sumY=0, x, y, z, avg;
// 圖片大小為 n*n,所以共有 n*n 個像素
for(int i=0; i<n*n; i++){
// r、g、b 分別代表 RGB 三原色數值
int r,g,b;
// 輸入一個像素的 RGB 值
cin>>r>>g>>b;
// RGB 轉換成 XYZ 色彩空間
// 使用標準轉換公式
x=0.5149*r+0.3244*g+0.1607*b;
y=0.2654*r+0.6704*g+0.0642*b;
// Y 代表亮度值,所以需要計算平均亮度
z=0.0248*r+0.1248*g+0.8504*b;
// 累加每個像素的 Y 值
sumY+=y;
// 輸出轉換後的 X、Y、Z 值
// 固定輸出小數點後 4 位
cout<<fixed<<setprecision(4)
<<x<<' '<<y<<' '<<z<<'\n';
}
// 計算所有像素的平均 Y 值
avg=sumY/(n*n);
// 輸出平均亮度
cout<<fixed<<setprecision(4)
<<"The average of Y is "<<avg<<'\n';
}
return 0;
}