Advertisement
Guest User

+sortowanie

a guest
Mar 28th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <math.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. string tab;
  10.  
  11. int licz,i,x;
  12. int sprawdz1(int x);
  13. int sprawdz1(int x)
  14. {
  15.     if (x>=2)
  16.     {
  17.         licz=0;
  18.         for(i=1; i<8; i++)
  19.             if(x==pow(2,i))
  20.             {
  21.                 licz++;
  22.                 break;
  23.             }
  24.         if(licz>0)
  25.             return 1;
  26.         else
  27.             return 0;
  28.     }
  29.     else
  30.         return 0;
  31. }
  32.  
  33. //===================================================
  34. void sortowanie(int tablica[], int rozmiar)
  35. {
  36.     for(int i=0; i<rozmiar; i++)
  37.     {
  38.         int flag=0;
  39.         for(int j=1; j<rozmiar-i; j++)
  40.         {
  41.             if(tablica[j-1] > tablica[j])
  42.             {
  43.                 swap(tablica[j-1], tablica[j]);
  44.                 flag=1;
  45.             }
  46.         }
  47.         if(flag==0)
  48.             break;
  49.     }
  50. }
  51. //===================================================
  52.  
  53. int slowo;
  54.  
  55. int main()
  56. {
  57.     ifstream pobierz;
  58.     pobierz.open("dane5-3.txt",ios::in);
  59.     if(!pobierz)
  60.     {
  61.         cerr << "Cant open" << endl;
  62.     }
  63.  
  64.     int tablica [10000];
  65.     for(int i = 0; i < 10000; i++)
  66.     {
  67.         tablica[i] = 0;
  68.     }
  69. /*
  70.     int ile = 0;
  71.     while(!pobierz.eof())
  72.     {
  73.         pobierz>>slowo;
  74.         if(sprawdz1(slowo)==1)
  75.         {
  76.             tablica[ile] = slowo;
  77.         }
  78.         cout<<ile<<") "<<tablica[i]<<endl;
  79.         ile++;
  80.     }
  81. */
  82.     for(int i = 0; i < 10000 ; i++)
  83.     {
  84.         pobierz>>slowo;
  85.         if(sprawdz1(slowo)==1)
  86.         {
  87.             tablica[i] = slowo;
  88.         }
  89.         //cout<<i<<") "<<tablica[i]<<endl;
  90.     }
  91.     pobierz.close();
  92.  
  93.     sortowanie(tablica,10000);//!!!!!!!!
  94.  
  95.     ofstream wyswietl;
  96.     wyswietl.open("WyswietlanieLiczb.txt",ios::out);
  97.     if(!wyswietl)
  98.     {
  99.         cerr << "Cant open" << endl;
  100.     }
  101.  
  102.     for(int i = 0; i < 10000; i++)
  103.     {
  104.         if(tablica[i]!=0)
  105.         {
  106.             cout<<i<<") "<<tablica[i]<<endl;
  107.             wyswietl<<tablica[i]<<endl;
  108.         }
  109.     }
  110.     wyswietl.close();
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement