We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intcheck_anagram(string,string);intmain(){intt;cin>>t;for(intx=0;x<t;x++){intcount=0;//No. of pairsstrings;cin>>s;for(inti=1;i<=s.length();i++){vector<string>str;//to store the sub string of length ifor(intj=0;j+i<=s.length();j++){str.push_back(s.substr(j,i));// pushing the sub string of length i }for(intp=0;p<str.size();p++){for(intq=p+1;q<str.size();q++){if(check_anagram(str[p],str[q]))count++;}}}cout<<count<<endl;}return0;}intcheck_anagram(strings1,strings2){inta1[26]={0},a2[26]={0};for(inti=0;i<s1.length();i++){a1[s1[i]-'a']++;}for(inti=0;i<s2.length();i++){a2[s2[i]-'a']++;}for(inti=0;i<26;i++){if(a1[i]-a2[i]!=0){return0;//two strings are not anagram}}return1;//two strings are anagram}
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
c++ code