Post by huangno1 on Feb 24, 2017 8:21:10 GMT -8
程式說明
艾莉要設計一座雲霄飛車的軌道,為了評估軌道的安全性,她將計算軌道高度變化量的平均值;如果平均變化量高於5,就被認為是太過危險而不能接受。
以五段的雲霄飛車為例,包含起點和終點共有六個端點,其高度為 0, 10, 7, 5, 9, 0,則高度變化量為10, 3, 2, 4, 9,平均為 (10+3+2+4+9)/5 = 28/5 > 5,因此無法接受。
本題將輸入一串以 0 開始,以 0 結束的整數值(起點和終點的高度必為 0),代表雲霄飛車軌道端點的高度。請輸出軌道的平均高度差,並判斷是否可接受(> 5 即不可接受)。輸出格式請參照以下範例。
輸入範例一
0 10 7 5 9 0
輸出範例一
Average 28/5 is not accepted.
輸入範例二
0 0
輸出範例二
Average 0/1 is accepted.
輸入範例三
0 1 2 3 0
輸出範例三
Average 6/4 is accepted.
***以下為參考程式***(注意!!複製貼上此程式碼,將對你沒好處)
#include <stdio.h>
int main()
{
int began = 0 , H = 0 , total = 0 , change = 0 , time = 1 ;
float ave = 0 ;
scanf("%d", &began );
while ( 1 )
{
scanf("%d", &H );
if( H == 0 )
{
if( H >= began )
{
change = H - began;
began = H;
}
else
{
change = began - H;
began = H;
}
total = total + change;
break;
}
else
{
if( H >= began )
{
change = H - began;
began = H;
}
else
{
change = began - H;
began = H;
}
total = total + change;
time++;
}
}
ave = (float)total / time;
if( ave > 5 )
{
printf("Average %d/%d is not accepted.", total , time );
}
else
{
printf("Average %d/%d is accepted.", total , time );
}
return 0;
}
艾莉要設計一座雲霄飛車的軌道,為了評估軌道的安全性,她將計算軌道高度變化量的平均值;如果平均變化量高於5,就被認為是太過危險而不能接受。
以五段的雲霄飛車為例,包含起點和終點共有六個端點,其高度為 0, 10, 7, 5, 9, 0,則高度變化量為10, 3, 2, 4, 9,平均為 (10+3+2+4+9)/5 = 28/5 > 5,因此無法接受。
本題將輸入一串以 0 開始,以 0 結束的整數值(起點和終點的高度必為 0),代表雲霄飛車軌道端點的高度。請輸出軌道的平均高度差,並判斷是否可接受(> 5 即不可接受)。輸出格式請參照以下範例。
輸入範例一
0 10 7 5 9 0
輸出範例一
Average 28/5 is not accepted.
輸入範例二
0 0
輸出範例二
Average 0/1 is accepted.
輸入範例三
0 1 2 3 0
輸出範例三
Average 6/4 is accepted.
***以下為參考程式***(注意!!複製貼上此程式碼,將對你沒好處)
#include <stdio.h>
int main()
{
int began = 0 , H = 0 , total = 0 , change = 0 , time = 1 ;
float ave = 0 ;
scanf("%d", &began );
while ( 1 )
{
scanf("%d", &H );
if( H == 0 )
{
if( H >= began )
{
change = H - began;
began = H;
}
else
{
change = began - H;
began = H;
}
total = total + change;
break;
}
else
{
if( H >= began )
{
change = H - began;
began = H;
}
else
{
change = began - H;
began = H;
}
total = total + change;
time++;
}
}
ave = (float)total / time;
if( ave > 5 )
{
printf("Average %d/%d is not accepted.", total , time );
}
else
{
printf("Average %d/%d is accepted.", total , time );
}
return 0;
}