+ 1

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

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. Input 1 butterfly flutterby Output 1 2 Input 2 home come Output 2 -1 My code https://code.sololearn.com/cF78EZYwNOfU/#

8th Oct 2018, 9:57 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
9 odpowiedzi
+ 3
Nilutpol Kashyap what is your query...?
8th Oct 2018, 10:02 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
common headers need to be included individually go through below link : https://www.sololearn.com/Discuss/1296954/?ref=app
8th Oct 2018, 10:06 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
Nilutpol Kashyap Remember that your is a C++ code, not C P.S. Dont open multiple times same question next time
8th Oct 2018, 12:35 PM
KrOW
KrOW - avatar
0
John Wells sir can you please help me with the above code. its not compiling. I have tried but it's not working. can you please help. thank you sir.
8th Oct 2018, 10:00 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
Ketan Lalcheta sir I have uploaded my question above and I have also uploaded my code link. but my code is not working. can you please help me by checking for the errors. thanks a lot for your help.
8th Oct 2018, 10:05 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
Ketan Lalcheta sir which header do I need. I have included stdio.h, conio.h and string.h. but it's still not working. the error message is as follows Compilation : Failed Program Programtest.c:4:1: error: unknown type name using using namespace std; ^ test.c:4:17: error: expected =, ,, ;, asm or __attribute__ before std using namespace std; ^ test.c:6:12: error: unknown type name string void store(string s,long long len,vector<long long> &dp){ ^ test.c:6:35: error: unknown type name vector void store(string s,long long len,vector<long long> &dp){ ^ test.c:15:1: error: unknown type name bool bool func(string a,string b){ ^ test.c:15:11: error: unknown type name string bool func(string a,string b){ ^ test.c:15:20: error: unknown type name string bool func(string a,string b){ ^ test.c: In function main: test.c:42:2: error: unknown type name string string A,B; ^ test.c:44:2: error: cin undeclared (first use in this function) cin >> A >> B; ^ test.c:44:2: note: each undeclared identifier is reported only once for each function it appears in test.c:48:5: warning: implicit declaration of function func [-Wimplicit-function-declaration] if(func(A,B)){ ^ test.c:50:20: error: request for member length in something not a structure or union long long len = A.length(); ^ test.c:54:8: error: subscripted value is neither array nor pointer nor vector if(A[i] == B[i]){ ^ test.c:54:16: error: subscripted value is neither array nor pointer nor vector if(A[i] == B[i]){ ^ test.c:59:3: error: cout undeclared (first use in this function) cout << ans << endl; ^ test.c:59:18: error: endl undeclared (first use in this function) cout << ans << endl; ^
8th Oct 2018, 10:09 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
KrOW thanks for the update sir. can you please help me with the code??
8th Oct 2018, 12:52 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
0
Nilutpol Kashyap Your code its saved like C code. Start with saving it like C++ code and update links here
8th Oct 2018, 1:04 PM
KrOW
KrOW - avatar
0
#include<stdio.h> #include<string.h> int main() { char s1[100],s2[100]; //int num1[26] = {0}, num2[26] = {0}, i = 0; int count=0,i=0; scanf("%s %s", s1,s2); int num1[26] = {0}, num2[26] = {0}; while (s1[i] != '\0') { num1[s1[i] - 'a']++; i++; } i = 0; while (s2[i] != '\0') { num2[s2[i] -'a']++; i++; } for (i = 0; i < strlen(s1); i++) { if (num1[i] != num2[i]) { printf("-1"); goto A; } } for (i = 0; i < strlen(s1); i++) { if (s1[i] == s2[i]) { count++; } } printf("%d",count); A: return 0; }
28th Mar 2022, 4:23 AM
Akhtar-ul Islam