Advertisement
Guest User

pr 2 siruri caractere

a guest
Jan 16th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int SortCuv(char cuv[])
  8. {
  9.     char aux;
  10.     int n = strlen(cuv);
  11.     for(int i = 0; i < n-1; i++)
  12.         for(int j = i+1; j < n; j++)
  13.         {
  14.             if(cuv[i] > cuv[j])
  15.             {
  16.                 aux = cuv[i];
  17.                 cuv[i] = cuv[j];
  18.                 cuv[j] = aux;
  19.             }
  20.  
  21.         }
  22. }
  23.  
  24. int main()
  25. {
  26.     ifstream fin("intrare.txt");
  27.     ofstream fout("iesire.txt");
  28.     char cuv1[255], cuv2[255], c1[255], c2[255];
  29.  
  30.     while(!fin.eof())
  31.     {
  32.         fin>>cuv1;
  33.         fin>>cuv2;
  34.         //cout<<"Inainte de sortare:"<<cuv1<<" "<<cuv2<<endl;
  35.         strcpy(c1, cuv1);
  36.         strcpy(c2, cuv2);
  37.         SortCuv(cuv1);
  38.         SortCuv(cuv2);
  39.         //cout<<"Dupa sortare:"<<cuv1<<" "<<cuv2<<endl;
  40.         if (!strcmp(cuv1, cuv2))
  41.             fout<<c1<<" "<<c2<<endl;
  42.     }
  43.     fin.close();
  44.     fout.close();
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement