#include <iostream>
using namespace std;
int main()
{
int n = 0;
cin >> n;
int arr[100];
int tmp;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = n - 1; i > 0; i--){
for(int j = 0; j < i; j++ ){
if(arr[j] > arr[j+1]){
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
cout << arr[0];
for(int i = 1; i < n; i++){
cout << " " << arr[i];
}
cout << endl;
if(arr[0] > 60){
cout << "best case" << endl;
}else{
for(int i = 0; i < n; i++){
if(arr[i] >= 60){
cout << arr[i-1] << endl;
break;
}
}
}
if(arr[n - 1] < 60){
cout << "worst case";
}else{
for(int i = 0; i < n; i++){
if(arr[i] >= 60){
cout << arr[i];
break;
}
}
}
return 0;
}
測資:
3
60 61 62試試看吧~
這些人全部及格了
修改過後還是NA
#include <iostream>
using namespace std;
int main()
{
int n = 0;
cin >> n;
int arr[100];
int tmp;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = n - 1; i > 0; i--){
for(int j = 0; j < i; j++ ){
if(arr[j] > arr[j+1]){
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
cout << arr[0];
for(int i = 1; i < n; i++){
cout << " " << arr[i];
}
cout << endl;
if(arr[0] >= 60){
cout << "best case" << endl;
}else{
for(int i = 0; i < n; i++){
if(arr[i] >= 60){
cout << arr[i-1] << endl;
break;
}
}
}
if(arr[n - 1] < 60){
cout << "worst case";
}else{
for(int i = 0; i < n; i++){
if(arr[i] >= 60){
cout << arr[i];
break;
}
}
}
return 0;
}