#include<stdio.h>
int main(){
int n, d;
int price[100][3] = {0};
int maxi_price = 0;//最高價
int mini_price = 0;//最低價
int number = 0;
int avg = 0;
scanf("%d %d", &n, &d);
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
scanf("%d", &price[i][j]);
}
}
//排序
for(int i = 0; i < n; i++){
for(int j = 0; j < 2; j++){
if(price[i][j] > price[i][j+1]){
int temp = price[i][j];
price[i][j] = price[i][j+1];
price[i][j+1] = temp;
}
}
}
for(int i = 0; i < n; i++){
maxi_price = price[i][2];
mini_price = price[i][0];
if((maxi_price - mini_price)>= d){//價差至少為d以上
number++;
avg = avg + (price[i][0] + price[i][1] + price[i][2]) / 3;
}
}
printf("%d %d", number, avg);
}
我的寫法哪裡有錯? 誰能幫幫我?
#include
int main(){
int n, d;
int price[100][3] = {0};
int maxi_price = 0;//最高價
int mini_price = 0;//最低價
int number = 0;
int avg = 0;
scanf("%d %d", &n, &d);
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
scanf("%d", &price[i][j]);
}
}
//排序
for(int i = 0; i < n; i++){
for(int j = 0; j < 2; j++){
if(price[i][j] > price[i][j+1]){
int temp = price[i][j];
price[i][j] = price[i][j+1];
price[i][j+1] = temp;
}
}
}
for(int i = 0; i < n; i++){
maxi_price = price[i][2];
mini_price = price[i][0];
if((maxi_price - mini_price)>= d){//價差至少為d以上
number++;
avg = avg + (price[i][0] + price[i][1] + price[i][2]) / 3;
}
}
printf("%d %d", number, avg);
}
我的寫法哪裡有錯? 誰能幫幫我?
我修改好了,是排序寫法出問題