1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Soloha48 [4]
3 years ago
14

Write a function that checks whether two words are anagrams. Two words are anagrams if they contain the same letters. For exampl

e, silent and listen are anagrams. The header of the function is: def isAnagram(s1, s2): (Hint: Obtain two lists for the two strings. Sort the lists and check if two lists are identical.)
Computers and Technology
1 answer:
marysya [2.9K]3 years ago
7 0

<u>C++ program for the checking if 2 strings are anagram :- </u>

#include<bits/stdc++.h>

using namespace std;

void isAnagram(string s1,string s2) //defining function

{

int an1[256]={},an2[256]={};//declare two count arrays of size 256 an1 and an2.

bool test=true;//taking a bool variable test = true for displaying the result..

for(int i=0;s1[i]&s2[i];i++) // iterating over both the strings.

{

an1[s1[i]]++;//increasing the count of the characters as per their ascii values in count array an1.

an2[s2[i]]++;//increasing the count of the characters as per their ascii values in count array an2.

}

for(int i=0;i<256;i++)//iterating over the count arrays..

{

if(an1[i]!=an2[i])//condition for not anagram.

{

cout<<"not an anagram"<<endl;

test=false;//making test false..

break;//coming out of the loop.

}

}

if(test)//if test is true only then printing..

cout<<"is an anagram"<<endl;

}

int main()

{

string s1,s2;//declaring two strings.

cout<<"Enter both the strings"<<endl;

cin>>s1>>s2;//prompting the strings..

if(s1.length()==s2.length()) //checking whether the lengths of string is same or not

isAnagram(s1,s2); //calling function

else

cout<<"not an anagram"<<endl;

return 0;

}

<u>Explanation</u>

A string is said to be an anagram string of other string if it has same characters but in different order or exactly the same.

for example:-  

string 1="silent"  

string 2="listen"

string 2 is an anagram of string 1.

void isAnagram(string s1,string s2) - This is the function having name isAnagram of void return type having parameters s1 and s2.

You might be interested in
What is the difference between a surge and a spike?
Anna [14]
D, I think. I may be wrong. Someone comment and tell me
3 0
3 years ago
Pls help I will mark you the brainliest
ehidna [41]

Answer:

c

Explanation:

6 0
3 years ago
Read 2 more answers
Jacob is a teacher and wants to sort his grades based on Test 1 and then on Test 2.
Pachacha [2.7K]
<span>He would click on the Test 1 column and press Sort, then click on the Test 2 column and press Sort. 
 It depends on what you learn because it says "shift"</span>
4 0
3 years ago
Read 2 more answers
I NEED A BIG BRAIN BOYO TO HELP ME
dlinn [17]
Yoooo whattt?? I don’t get this but idek
7 0
3 years ago
The __is the temporary storange location for text when it is cut from a document
enot [183]
The informal answer to your question is "clipboard". However, there isn't such a thing as the "clipboard". The people who came up with the idea of the clipboard use that nomenclature to describe the location in memory where that copied data resides. So the formal answer to your question is memory or RAM.
3 0
3 years ago
Other questions:
  • April 107 90 29 31 66 0.344
    8·1 answer
  • You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
    7·1 answer
  • A technology company only hires applicants who are under the age of 30. This company could face possibly _________ consequences
    9·2 answers
  • A flat-panel detector is exposed with nothing between the x-ray tube and detector. 5 images were acquired on 5 different days us
    6·1 answer
  • If you are a member of a security penetration testing team, and you identify vulnerabilities and exploits, what should you obtai
    11·1 answer
  • Create a class 'ProblemSolution' with following characteristics A public method 'solution' without parameters and return type is
    14·1 answer
  • A selected graphic appears surrounded by a(n) ______, which has small squares and circles around its edges.
    7·1 answer
  • Capstone Project part 11 quiz
    6·1 answer
  • Please help me with coding!
    7·2 answers
  • Suppose the cache access time is 10ns, main memory access time is 200ns, and the cache hit rate is 90%. Assuming parallel (overl
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!