#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int howmany,ALL,Q = 1,bs=0,ws; //幾筆資料 ,同,後面用到,bestcase,worsecase
cin >> howmany ;
ALL = howmany;
int point[howmany];
while(howmany > 0){ //計算資料數 每完成一比-1
cin >> point[howmany]; //in
if(point[howmany] > 100 ){
point[howmany] = 100;
}
else if(point[howmany] < 0){
point[howmany] = 0;
}
howmany = howmany - 1;
}
sort(point, point + ALL+1);
ws = point[ALL];
while(ALL > 0){
cout << point[Q]<<" ";
if(point[Q] < 60){
point[Q] > bs;
bs = point[Q]; }
else{
if(point[Q] < ws){
ws = point[Q]; }
}
ALL = ALL - 1;
Q++;
}
if(bs == 0){
cout<<endl<<"best case"<<endl; }
else{
cout <<endl<<bs<<endl;
}
if(ws < 60){
cout<<"worst case"; }
else{
cout << ws;
}
}
#include
#include
using namespace std;
int main(){
int howmany,ALL,Q = 1,bs=0,ws; //幾筆資料 ,同,後面用到,bestcase,worsecase
cin >> howmany ;
ALL = howmany;
int point[howmany];
while(howmany > 0){ //計算資料數 每完成一比-1
cin >> point[howmany]; //in
if(point[howmany] > 100 ){
point[howmany] = 100;
}
else if(point[howmany] < 0){
point[howmany] = 0;
}
howmany = howmany - 1;
}
sort(point, point + ALL+1);
ws = point[ALL];
while(ALL > 0){
cout << point[Q]<<" ";
if(point[Q] < 60){
point[Q] > bs;
bs = point[Q]; }
else{
if(point[Q] < ws){
ws = point[Q]; }
}
ALL = ALL - 1;
Q++;
}
if(bs == 0){
cout<<endl<<"best case"<<endl; }
else{
cout <<endl<<bs<<endl;
}
if(ws < 60){
cout<<"worst case"; }
else{
cout << ws;
}
}
陣列的範圍是從0開始到陣列長度-1,所以你很多地方都超出範圍了