C++ code for the above question-
#include<bits/stdc++.h>
using namespace std;
int main() {
string s1,s2;
cin>>s1>>s2; // input both strings
int a[26]={0},b[26]={0}; // for counting the number of occurance of each alphabet
for(int i=0;i<s1.length();i++){
a[s1[i]-'a']++; // counting the
occurance of each alphabet in s1
}
for(int i=0;i<s2.length();i++){
b[s2[i]-'a']++; // counting the
occurance of each alphabet in s2
}
//check if all alphabet occurs equal number of
times.
int flag=0;
for(int i=0;i<26;i++){
if(a[i]!=b[i]){ // checking if the
count of a particular alphabet
//in both
string is different
flag=1;
break;
}
}
if(flag==0){
cout<<"One string is anagram
of other.";
}
else{
cout<<"One string is not the
anagram of other.";
}
return 0;
}
Code-
Input and Output-
Explanation-
One string is the anagram of other if the number of occurance of each alphabet in both string is same. So,in the above code,first the number of occurance of each alphabet for both string s1 and s2 is calculated in array a and b respectively.Then,I have checked if the count of each alphabet in array a and b is same or not.
If the answer helped then please upvote.And for any queries,please comment.
using simple and basic C++, read two strings and determine if one is an anagram of...
I need a program in fortran 95 that can detect if two strings are anagrams Anagram Detector Due by Friday 12 April 2019 11:59 PM Program Overview: This program will be able to determine if two inputted texts are anagrams of one another Relevant Details and Formulas: An anagram of a text is a rearrangement of the letters such that it forms another, usually intelligible, set of words. Capitalization is not important and any white space, punctuation, or other non-letter...
Anagram Detector Due by Friday 12 April 2019 11:59 PM Program Overview: This program will be able to determine if two inputted texts are anagrams of one another. Relevant Details and Formulas: An anagram of a text is a rearrangement of the letters such that it forms another, usually intelligible, set of words. Capitalization is not important and any white space, punctuation, or other non-letter symbols should be ignored. Program Specification: * Prompt the user for a pair of text...
using c only You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator), but can be...
using c and pointers only 1. You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator),...
Do not use global variables. Pass your arguments by value and by reference (address). Using arrays and modular programming techniques (i.e. functions), write a C-program which accepts two strings and determines whether one string is an anagram of the other, that is, whether one string is a permutation of the characters in the other string. For example, “dear” is an anagram of “read”, as is “dare”. Also, anagrams of “monday” could be “don may” or “do many”, but not “mad”....
A simple instrument consists of two metal strings stretched parallel to one another and attached at both ends to boards perpendicular to the strings. The tension is the same in both strings, and the length of the strings is ` = 35.0 cm. The first string has a mass m = 8.00 g and generates middle C (frequency f = 262 Hz) when vibrating in its fundamental mode. a) What is the tension in the first string? b) If the...
PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here do { // program here }while (true); } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...
Consider that two strings are perms of one another if the same number of every character is present in both. Thus the two strings ‘aabcc’ and ‘ccbaa’ are perms, for each has two a’s, one b and 2 c’s. Another example: the strings ‘xyyz’ and ‘yxz’ are not perms, for one has two y’s and the other has only one. Take two lists of strings. Find how many members of the first have a perm in the second using Phyton...
Declare a function that checks whether two strings are equal. In function main, read two strings, call the function and print “equal” if the strings are equal and “not equal” otherwise. The input strings contain at most 50 characters. Example of input: alphabet alphabet Corresponding output: equal Example of input: week weak Corresponding output: not equal In C Language
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...