Conditions of the problem: to create a program that checks whether the given strings are "relatives". Relatives are words that are written with the same characters. An example of such lines is "ram" and "drum". Because This is an Olympiad task, then the execution time and weight are important. For some reason, if there are duplicate characters in the word, not parents go to the conclusion. Can someone explain why this is happening and advise solutions for optimization?
#include <iostream> #include <string> using namespace std; int main() { string s1; string s2; getline(cin, s1); getline(cin, s2); bool isEqual[s2.length()]; bool answ = true; for (int i=0;i<s1.length();i++){ for (int y=0;y<s2.length();y++){ if(s2[y] == s1[i]){ isEqual[y]=true; break; } } } for (int i=0; i < s2.length();i++){ if (isEqual[i] == false){ cout << "not parents"; return 0; } } cout << "parents"; }