Function customCompareThe function/method customCompare accepts two arguments – str1 and str2 representing two string values.
The function/method customCompare must return 1 if the upper case alphabets in str1 match the upper case alphabets in str2 in the same order of their occurrence. Else the function must return 0.
Your task is to implement the function customCompare so that it passes all the test cases.
IMPORTANT: Do not write the main() function as it is already defined.
Example Input/Output 1:
Input:
AbcdEFghi
jklAmnEopF
Output:
1
Explanation:
The upper case alphabets in the string AbcdEFghi are A, E and F.
The upper case alphabets in the string jklAmnEopF are A, E and F.
Here the upper case alphabets in both string values are the same.
Hence the output is 1.
Example Input/Output 2:
Input:
eLEphanT
gETpLane
Output:
0
Example Input/Output 3:
Input:
prime-N-U-M-B-E-R-S
NUMBERS12345
Output:
1
#include <stdio.h>
#include <stdlib.h>
int customCompare(char str1[], char str2[])
{
char s1[40],s2[40];
int a=0,b=0;
int len=(strlen(str1)>strlen(str2))?strlen(str1):strlen(str2);
for(int i=0;i<len;i++)
{
if(i<strlen(str1) && isupper(str1[i])){
s1[a]=str1[i];
a++;
}
if(i<strlen(str2) && isupper(str2[i])){
s2[b]=str2[i];
b++;
}
}
s1[a]=' ';
s2[b]=' ';
if(strcmp(s1,s2)==0)
return 1;
else
return 0;
}
int main()
{
char str1[101], str2[101];
scanf("%sn%s", str1, str2);
printf("%d", customCompare(str1, str2));
return 0;
}