SHARE
TWEET

Untitled

a guest Oct 10th, 2019 81 in 169 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //algorytm sprawdzajacy, czy dwa slowa zlozone wylacznie z liter "X" i "Y" sa anagramami
  2. #include <iostream> //endl umieszcza w strumieniu znak końca wiersza i opróznia stumień
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. bool sprawdz (string s1, string s2)
  7. {
  8.  int endl=s1.size();
  9.  if (endl!=s2.size()) return false;
  10.  else
  11.  {
  12.   int T1[2]={0,0}, T2[2]={0,0};
  13.   for (int i=0;i<endl;i++)
  14.   {
  15.    if (s1[i]=='X') T1[0]++;
  16.    else T1[1]++;
  17.    if (s2[i]=='X') T2[0]++;
  18.    else T2[1]++;
  19.   }
  20.   for (int i=0;i<2;i++)
  21.    if (T1[i]!=T2[i]) return false;
  22.  }
  23.  return true;
  24. }
  25.  
  26. int main()
  27. {
  28.  string s1, s2;
  29.  cout<<"podaj pierwszy wyraz: ";
  30.  cin>>s1;
  31.  cout<<"podaj drugi wyraz: ";
  32.  cin>>s2;
  33.  if (sprawdz(s1,s2)) cout<<"\nslowa sa anagramami"<<endl;
  34.  else cout<<"\nslowa nie sa anagramami"<<endl;
  35.  return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top