Facebook
From Gracious Frog, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 347
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. using namespace std;
  5. struct zawodnik
  6. {
  7. string imie;
  8. string nazwisko;
  9. unsigned punkty;
  10. };
  11. void bubble(unsigned n, zawodnik tab[]);
  12. void wypisz(unsigned n, zawodnik tab[]);
  13. int main()
  14. {
  15. ifstream odczyt("wyniki.txt");
  16. zawodnik tab[100];
  17. unsigned i=0;
  18. while(!odczyt.eof())
  19.  {
  20.  odczyt>>tab[i].imie;
  21.  odczyt>>tab[i].nazwisko;
  22.  odczyt>>tab[i].punkty;
  23.  i++;
  24.  }
  25.  odczyt.close();
  26. unsigned n=i;
  27. cout<<"Wyniki zawodnikow: "<<endl;
  28. for(int i=0;i<n;i++)
  29.  {
  30.  cout<<tab[i].imie<<" "<<tab[i].nazwisko<<" "<<tab[i].punkty<<endl;
  31.  }
  32. }
  33. void bubble(unsigned n, zawodnik tab[])
  34. {
  35.  zawodnik pom;
  36.  for(int i=0;i<n;i++)
  37.  for(int j=0;j<n-1-i;j++)
  38.  {
  39.   if(tab[j].punkty>tab[j+i].punkty)
  40.   {
  41.   pom=tab[j];
  42.   tab[j]=tab[j+1];
  43.   tab[j+i]=pom;
  44.  }
  45.  }
  46. }
  47. void wypisz(unsigned n, zawodnik tab[])
  48. {
  49.     for(int j=0;j<n;j++)
  50.     cout<<tab[j].imie<<" "<<tab[j].nazwisko<<" "<<tab[j].punkty<<endl;
  51. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Obese Lemur cpp 6 Years ago.