Skip to content

CGreenP/NPTEL-Introduction-to-Programming-in-C-Assignment-6-Question-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

NPTEL-Introduction-to-Programming-in-C-Assignment-6-Question-1

NPTEL Introduction to Programming in C Assignment 6 Question 1

Question 1

We say that a string 's' is an anagram of another string 't' if the letters in 's' can be rearranged to form 't'.

For example, "butterfly" is an anagram of "flutterby", since a rearrangement of the first word results in the second.

We say that a position 'i' in 's' and 't' match, if 's' is an anagram of 't', and s[i]==t[i].

In this question, you will be given two words, 's' and 't'. You have to output the number of matching positions if s is an anagram of t, and -1 if s is not an anagram of t.

Input

The input consists of two lines. The first line contains the first string, with length <= 100 characters. The second line contains the second string, with length <= 100 characters.

Output

If the first string is an anagram of the second string, then output the number of matching positions. Otherwise, print -1.

Sample Input 1

butterfly
flutterby

Sample Output 1

2

Sample Input 2

home
come

Sample Output 2

-1

Sample Input 3

anarchy
anerchy

Sample Output 3

-1

Sample Input 4

cyclonepic
enolcyccpi

Sample Output 4

1

Sample Input 5

turingmachine
turingmachime

Sample Output 5

-1

Sample Input 6

abacbstuvab
baabctsuavb

Sample Output 6

3

About

NPTEL Introduction to Programming in C Assignment 6 Question 1

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages