Guest User

Untitled

a guest
Feb 7th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 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. int liczba;
  54. liczba=ludzie[j+1].pkt;
  55. ludzie[j+1].pkt=ludzie[j].pkt;
  56. ludzie[j+1].pkt=liczba;
  57. }
  58. }
  59. }
  60.    
  61. //wypis pierwszej 30 zawodnikow
  62. cout<<"Wyniki zawodow: ";
  63. for(int i=0;i<30;i++)
  64. {
  65.     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;
  66. }
  67.  
  68.  
  69. system("pause");
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment