請把以下程式碼複製到你電腦跑跑看
我百分之百確定完全沒問題
可是送上去都是WA格式不符
#include<stdio.h>
int main() {
short n, i, r, g, b;
float t, sum = 0.0;
while( scanf("%hd", &n)!=EOF ) {
sum = 0.0;
n *= n;
for (i=0; i<n; i++) {
scanf("%hd %hd %hd", &r, &g, &b);
t = 0.2654*r + 0.6704*g + 0.0642*b;
sum += t;
printf("%.4f %.4f %.4f\n", 0.5149*r + 0.3244*g + 0.1607*b, t, 0.0248*r + 0.1248*g + 0.8504*b);
}
printf("The average of Y is %.4f", sum/n);
}
return 0;
}
我知道你準備說用short會overflow
好 那我改用int 跟 double
一樣WA
#include<stdio.h>
int main() {
int n, i, r, g, b;
double t, sum = 0.0;
while( scanf("%d", &n)!=EOF ) {
sum = 0.0;
n *= n;
for (i=0; i<n; i++) {
scanf("%d %d %d", &r, &g, &b);
t = 0.2654*r + 0.6704*g + 0.0642*b;
sum += t;
printf("%.4f %.4f %.4f\n", 0.5149*r + 0.3244*g + 0.1607*b, t, 0.0248*r + 0.1248*g + 0.8504*b);
}
printf("The average of Y is %.4f", sum/n);
}
return 0;
}
有可能是四捨五入的問題喔~
題目有說y的平均要四捨五入到小數第四位
不對
我剛剛發現不處理四捨五入也會過==
你的不會過是因為忘記"換行"了
printf("The average of Y is %.4f\n", sum/n);