Advertisement
arturParchem

czy to anagram

May 13th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void sortowanie(string &d)
  4. {
  5.     int n=d.size();
  6. for(int j=0;j<n-1;j++)
  7.     for(int i=0;i<n-1-j;i++)
  8.         if(d[i]>d[i+1])
  9.             swap(d[i], d[i+1]);
  10. }
  11. int main()
  12. {
  13. string d,c;
  14. cout<<"Podaj pierwszy anagram(tylko male litery): "<<endl;
  15. cin>>d;
  16. cout<<"Podaj drugi anagram(tylko male litery): "<<endl;
  17. cin>>c;
  18. sortowanie(d);
  19. sortowanie(c);
  20. int dlc=c.size();
  21. int dld=d.size();
  22. if(dlc==dld)
  23. {
  24.     for(int i=0;i<=dlc;i++)
  25.    {
  26.        if(d[i]!=c[i])
  27.        {
  28.            cout<<"To nie sa anagramy";
  29.            return 0;
  30.        }
  31.    }
  32. }else
  33. {
  34.     cout<<"To nie sa anagramy";
  35.     return 0;
  36. }
  37.  
  38. cout<<"To sa anagramy";
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement