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
Requirements description:
Andrews [41]

Answer:

The code has been written in Java.

The source code of the file has been attached to this response. The source code contains comments explaining important lines of the program.

A sample output got from a run of the application has also been attached.

To interact with the program, kindly copy the code into your Java IDE and save as Cafe.java and then run the program.

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
75f69c356ebff0797de4ffcfb6f8c22e.png
8 0
2 years ago
_______is a term which describes how the operating system will interrupt the execution of an application when an application of
a_sh-v [17]

Answer:

scheduling

Explanation:

Scheduling- it is referred to as assigning a task to complete the goal or work on time. he works can include data flow, processing of data, etc.

There are two main types of scheduling

1) Preemptive process

2) Non- preemptive process

Preemptive process -  in this process, priority is given to important tasks rather than less important tasks. the current task can be held for an important task

Non-preemptive process -  It is referred to that process when the predefined schedule follows. In this  process, next task executed only when current task finish

6 0
2 years ago
You want to chart your daily water intake over the next three months. Which type of chart would be best for this purpose? Line P
diamong [38]

The best type of chart to illustrate the daily water intake that you would be taking in the next three months would be (A) Line.

Line is most suitable because it will show the progression – be it the increase and decrease – of your water intake clearly, compared to using bar, which is more suitable if you would like to contrast your water intake with your soda intake, for example.

7 0
2 years ago
There are three levels of FDA approval for medical devices, with Level 1 being advanced technological products such as pacemaker
FromTheMoon [43]

<em>The answer is FALSE. </em>

<em>3 Levels of FDA's are: </em>

  • <em>Class 1 - these are devices that contains low risk to the user or patient. Examples: bandages, bedpans, stethoscopes.  </em>
  • <em>Class 2 - devices that has moderate risk to the user such as wheelchairs. </em>
  • <em>Class 3 - devices that implements and support life forms. These can be either inside (implanted) or not. Examples of this are: pacemakers and implants. </em>

<em />

5 0
3 years ago
Write commands to carry out the following commands: a) Print all lines containing the string John. b) Print all lines where a wo
egoroff_w [7]

Answer:

see explaination

Explanation:

1.

1. grep 'John' FileName

2. grep '^\J' FileName

3. grep 'stopped$' FileName

4. grep -v -e 'was' FileName

5. grep -E '^(k|K)' FileName

2.

#print the message to create subdirectory

echo "Creating a subdirectory to copy current directory files into named 'sub'"

#create subdirectory

mkdir sub

echo "Directory successfully created"

#Copy the files in the current working directory to created subdirectory

echo "Copying files of current directory into newly created subdirectory"

rsync -a --exclude='sub' * sub

#display the message to copy the files

echo "Copying operation completed successfully"

echo "Now deleting the created subdirectory along with its contents"

rm -rf sub

#indicated the message completion of task

echo "Operation completed successfully."

3.

#prompt and read the first number

echo "Enter the first number: "

read x

echo "Enter the second number: "

read y

#Compute arithmetic operations and store in the

#respective variable

addition=$(($x + $y))

subtraction=$(($x - $y))

multiplication=$(($x * $y))

division=$(($x / $y))

#print the values

echo "Addition of $x and $y is $addition"

echo "Subtraction of $x and $y is $subtraction"

echo "Multiplication of $x and $y is $multiplication"

echo "Division of $x and $y is $division"

3 0
3 years ago
Other questions:
  • Isabella's manager has asked her to write up a _____ that describes their company's interest in developing a custom software sol
    13·1 answer
  • Which type of system must you connect to and use to make changes to Active Directory?
    15·1 answer
  • Rikki has had several problems at work recently. Her printer isn't printing correctly, copies from the copy machine come out wit
    8·2 answers
  • Before sharing a document, you must first save the document to
    12·1 answer
  • To save a document with a new name, click _______ in the navigation bar and enter a new filename.
    12·1 answer
  • What may happen if there is too much harmony in a design?
    14·1 answer
  • Which item is used for formatting in responsive web design?
    6·1 answer
  • What output is produced by the following code? Integer first = new Integer(7); Integer second = first; if (first == second) Syst
    15·1 answer
  • The auxiliary device used to store large volume of data and program for future is called​
    10·1 answer
  • Why are my images blocked on brainly<br><br> i just see gray and on every avatar and image
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!