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]
4 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]4 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
.Pretend you are ready to buy a new computer for personal use.First, take a look at ads from various magazines and newspapers an
andriy [413]

Answer:

Brainly is not meant to give paragraph answers to large questions.

In a computer (desktop)

There are 8-9 main components to a PC

Motherboard

CPU

GPU (for gamers)

RAM

SSD

HDD

PSU

Cooling fans (for AMD processors stock fans are included)

Case (some fans included)

I personally build my computers (desktops) as its cheaper and I won't have to pay a build fee.

7 0
4 years ago
Stanford Rosenberg Computing wants to establish an assembly line for producing a new product, the Personal Digital Assistant (PD
Elina [12.6K]

Answer:

d what is the efficiency of this assembly line assignment?

8 0
4 years ago
Which of the following is the MOST important consideration when planning your budget?
nata0808 [166]
<span>Budget for fixed expenses before flexible expenses.</span>
5 0
4 years ago
Read 2 more answers
The users, groups, logins, and roles that have access to a server are called ________________. a. ids b. permissions c. principa
SVETLANKA909090 [29]
<span>The users, groups, logins, and roles that have access to a server are called securables. Correct answer: D
</span><span>A securable is anything that can have permissions granted, denied, or revoked on in SQL Server, while p</span>ermission is used to grant a user account access to a database.

8 0
4 years ago
When is a base case needed for recursive processing?
Oksanka [162]

Answer: Recursive processing or recursion is the technique in which a code calls itself in the same program in a direct or indirect manner in the computer program field.In general ,a stage of the procedure appeals the procedure itself.

Base case is the case required for the stopping of the recursion.After termination the returning process starts with the help of hierarchy calling. If there is no occurrence of base,then infinite recursion can take place.

                 

3 0
3 years ago
Other questions:
  • Consider an interface p ublic interface NumberFormatter { String format (in n); } Provide four classes that implement this inter
    15·1 answer
  • If someone receives a shock, or a piece of equipment is throwing sparks or arcing you should try to pull them away from the sour
    7·1 answer
  • True or false? Opinionated websites can still be credible. A. True B. False
    15·2 answers
  • What tool do you use to secure remote access by users who utilize the internet??
    7·1 answer
  • Discuss some design considerations that you should keep in mind when you want to design a professional-looking flyer or newslett
    5·2 answers
  • The strategy in which you periodically look away from the text and ask yourself about the material is called the
    8·2 answers
  • Only the Windows Server 2016 Standard and Datacenter editions are compatible with the common language runtime used in Microsoft
    7·1 answer
  • Which type of security policy is intended to provide a common understandingof the purposes for which an employee can and cannot
    15·1 answer
  • How can users open a shared worksheet if they do not have Excel installed on a computer? visit Microsoft’s website use Office365
    6·1 answer
  • A form of encryption that uses only one key to encrypt and decrypt a file. This is a less
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!