Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- fstream comeIn, outBitch;
- string linia, tekst[500], bufor;
- int nr=0, dlugosc=0;
- outBitch.open("posortowane.txt",ios::out);
- comeIn.open("nieposortowane.txt", ios::in);
- if(comeIn.good()==false)
- {
- cout<<"Nie mozna otworzyc pliku!(nieposortowane.txt)";
- }
- while(getline(comeIn, linia))
- {
- tekst[nr]=linia;
- dlugosc=tekst[nr].length();
- nr++;
- }
- for(int k=0; k<dlugosc; k++)
- {
- for(int j=0; j<nr; j++)
- {
- for(int i=0; i<nr; i++)
- {
- bufor=tekst[i];
- if(int(tekst[i+1][k])<int(tekst[i][k]))
- {
- tekst[i]=tekst[i+1];
- tekst[i+1]=bufor;
- if(dlugosc>1)
- {
- if(int(tekst[i+1][k-1])<int(tekst[i][k-1]))
- {
- tekst[i]=tekst[i+1];
- tekst[i+1]=bufor;
- }
- }
- }
- }
- }
- }
- for(int i=0; i<=nr; i++)
- {
- cout<<tekst[i]<<endl;
- outBitch<<tekst[i]<<endl;
- }
- outBitch.close();
- comeIn.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement