#35130: c++


shane950517@gmail.com (ㄟ不是)

學校 : 國立臺中高級工業職業學校
編號 : 166971
來源 : [60.249.14.165]
最後登入時間 :
2024-02-28 10:14:56
b964. 1. 成績指標 -- 2016年3月apcs | From: [122.118.4.69] | 發表日期 : 2023-05-10 20:20

#include <iostream>
#include <algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
 int std,std1,score1,score2;
 cin>>std;
 std1=std-1;
 int score[20];
 for( int i=0; i<std; i++ )
 {  
  cin >> score[i];
 }
 sort(score,score+std);
 for( int i=0; i<std; i++ )
 {  
  cout << score[i] << " " ;
 } 
 cout <<'\n';
 
 for(int i = std-1; i >= 0; i-- )
 {
        if (score[i] < 60) 
  {
     score1 = i;
  break;
  }
 }
 score1=score1+1;
   score2=score1-1;     
//------------------------------------------ 
 if(score[0]>=60)
 {
  cout << "best case"<<'\n'<<score[0];
 }
 else
 {
  if(score[0]<60 and score[std1]>=60)
  {
   cout<<score[score2]<<'\n'<<score[score1];
  }
  else
  {
   cout<<score[std1]<<'\n'<< "worst case ";
  }
 }

 return 0;
}

 
#38071: Re: c++


shane950517@gmail.com (ㄟ不是)

學校 : 國立臺中高級工業職業學校
編號 : 166971
來源 : [60.249.14.165]
最後登入時間 :
2024-02-28 10:14:56
b964. 1. 成績指標 -- 2016年3月apcs | From: [122.118.4.52] | 發表日期 : 2023-10-23 22:50



#include <iostream>
#include <algorithm>

using namespace std;

int a[25];

int main()
{
    int n, low = -1, high = -1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        if (a[i] < 60) {
            low = a[i];
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] >= 60) {
            high = a[i];
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        cout << a[i] << " ";
    }
    cout << '\n';

    if (low != -1) {
        cout << low << '\n';
    }
    else {
        cout << "best case" << '\n';
    }
    if (high != -1) {
        cout << high << '\n';
    }
    else {
        cout << "worst case" << '\n';
    }
}

 
ZeroJudge Forum