Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int verifAparitii(char s[], char c)
- {
- int aparitii = 0;
- for (int i = 0; i < strlen(s); i++)
- if (s[i] == c)
- aparitii++;
- return aparitii;
- }
- bool anagrame(char s1[], char s2[])
- {
- int n = strlen(s1);
- int m = strlen(s2);
- for (int i = 0; i < n; i++)
- if(s1[i]!=' ')
- if (verifAparitii(s1, s1[i]) != verifAparitii(s2, s1[i]))
- return false;
- return true;
- }
- int main()
- {
- char s1[100], s2[100];
- cin.get(s1, 99);
- cin.get();
- cin.get(s2, 99);
- if (anagrame(s1, s2))
- cout << "da";
- else
- cout << "nu";
- cout << endl << endl;
- system("pause");
- return 0;
- }
- -------alta rezolvare---
- #include<iostream>
- #include<string>
- using namespace std;
- void citireSiruri(char s1[], char s2[])
- {
- cin.get(s1, 29);
- cin.get();
- cin.get(s2, 29);
- }
- bool verifLungimi(char s1[], char s2[])
- {
- int count1 = 0, count2 = 0;
- for (int i = 0; i < strlen(s1); i++)
- if (s1[i] != ' ')
- count1++;
- for (int i = 0; i < strlen(s2); i++)
- if (s2[i] != ' ')
- count2++;
- if (count1 != count2)
- return false;
- return true;
- }
- bool anagrame(char s1[], char s2[])
- {
- if (!verifLungimi(s1, s2))
- return false;
- int aparitii[26] = { 0 };
- for(int i=0;i<strlen(s1);i++)
- if (s1[i] != ' ')
- {
- int a = s1[i];
- aparitii[a - 97]++;
- }
- for (int i = 0; i<strlen(s2); i++)
- if (s2[i] != ' ')
- {
- int a = s2[i];
- aparitii[a - 97]--;
- }
- for (int i = 0; i < 26; i++)
- if (aparitii[i] != 0)
- return false;
- return true;
- }
- int main()
- {
- char s1[50], s2[50];
- citireSiruri(s1, s2);
- if (anagrame(s1, s2))
- cout << "sunt anagrame";
- else
- cout << "nu sunt anagrame";
- cout << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement