Guest User

Untitled

a guest
Feb 7th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <cstdlib>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. struct zawodnik
  12. {
  13.     string imie;
  14.     int skok;
  15.     int styl;
  16.     int pkt;
  17.    
  18. };
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. int main()
  27. {
  28.     srand( time( NULL ) );
  29.     fstream IN;
  30.            
  31.             IN.open("plik.txt", ios::in);    // fstream wejściowy
  32.            
  33.     zawodnik ludzie[50];
  34.     for(int i=0; i<50; i++)
  35.    {
  36.     IN>>ludzie[i].imie;
  37.    }    
  38.  
  39.  
  40. for(int i=0; i<50; i++)
  41. {
  42.     ludzie[i].skok = rand()%100 + 200;
  43.     ludzie[i].styl = rand()%10;
  44.     ludzie[i].pkt = ludzie[i].skok + (2*  ludzie[i].styl);
  45. };
  46.    
  47.     //sortowanie najlepszej 30'
  48.    
  49.     for(int i=50;i>0;i--){
  50.         for(int j=0;j<i;j++){
  51.             if(ludzie[j].pkt<ludzie[j+1].pkt)
  52.             {
  53.                 struct zawodnik tmp=ludzie[j];
  54.                 ludzie[j]=ludzie[j+1];
  55.                 ludzie[j+1]=tmp;
  56.             }
  57.         }
  58.     }    
  59.    
  60. //wypis pierwszej 30 zawodnikow
  61. cout<<"Wyniki zawodow: ";
  62. for(int i=0;i<30;i++)
  63. {
  64.     cout<<endl<<endl<<i+1<<"."<<ludzie[i].imie<<endl<<"Suma pkt: "<<ludzie[i].pkt<<endl<<"Skok w m: "<<ludzie[i].skok<<endl<<"Pkt za styl: "<<ludzie[i].styl;
  65. }
  66.  
  67.  
  68. system("pause");
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment