Advertisement
Guest User

Untitled

a guest
Sep 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     fstream comeIn, outBitch;
  9.     string linia, tekst[500], bufor;
  10.     int nr=0, dlugosc=0;
  11.     outBitch.open("posortowane.txt",ios::out);
  12.     comeIn.open("nieposortowane.txt", ios::in);
  13.     if(comeIn.good()==false)
  14.     {
  15.         cout<<"Nie mozna otworzyc pliku!(nieposortowane.txt)";
  16.    }
  17.    while(getline(comeIn, linia))
  18.    {
  19.        tekst[nr]=linia;
  20.        dlugosc=tekst[nr].length();
  21.        nr++;
  22.    }
  23.    for(int k=0; k<dlugosc; k++)
  24.    {
  25.        for(int j=0; j<nr; j++)
  26.        {
  27.            for(int i=0; i<nr; i++)
  28.            {
  29.                bufor=tekst[i];
  30.                if(int(tekst[i+1][k])<int(tekst[i][k]))
  31.                {
  32.                    
  33.                    tekst[i]=tekst[i+1];
  34.                    tekst[i+1]=bufor;
  35.                    if(dlugosc>1)
  36.                     {
  37.                         if(int(tekst[i+1][k-1])<int(tekst[i][k-1]))
  38.                        {
  39.                            tekst[i]=tekst[i+1];
  40.                            tekst[i+1]=bufor;
  41.                        }
  42.                    }
  43.                }
  44.            }
  45.        }
  46.    }
  47.    for(int i=0; i<=nr; i++)
  48.    {
  49.        cout<<tekst[i]<<endl;
  50.        outBitch<<tekst[i]<<endl;
  51.    }
  52.    outBitch.close();
  53.    comeIn.close();
  54.    return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement