Advertisement
eimkasp

C++ OLIMP akcija

Dec 5th, 2011
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.   int n,m;
  10.   double ats= 0;
  11.   double ats2 = 0;
  12.   int Prek[100];
  13.   int temp;
  14.   ifstream fd("akcija.in");
  15.   ofstream fr("akcija.out");
  16.   fd >> m >> n;
  17.   for (int i = 1; i <= n; i++){
  18.     fd >> Prek[i];
  19.     //cout << Prek[i] << endl;
  20.   }
  21. cout << "-----" << endl;
  22.     for (int i = 1; i <= n ; i++) {
  23.         for (int j = 1; j <= n ; j++) {
  24.             if (Prek[j] > Prek[j+1] && Prek[j+1] > 0){
  25.                 temp = Prek[j];
  26.                 Prek[j] = Prek[j+1];
  27.                 Prek[j+1] = temp;
  28.             }
  29.     }
  30. }
  31.     for (int i = 1; i <= m ; i++) {
  32.         ats = ats + Prek[i];
  33.     }
  34.  
  35.     for (int i = n; i > n-m ; i--) {
  36.         ats2 = ats2 + Prek[i];
  37.     }
  38.     ats2 = ats2 / 100;
  39.     ats2 = Prek[n-m+1] / ats2;
  40.     ats = ats / 100;
  41.     ats = Prek[1] / ats;
  42.     cout << ats2<< endl;
  43.    
  44.     if (ats2 > ats) {
  45.         fr << setprecision(8) << ats2;}
  46.     else {fr << setprecision(8) << ats;}
  47.   return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement