Coding Practice

Write a C Program to check twin string or not

Twin String

2. Two strings s1 and s2 will be called “Twin String” if the following conditions are matched: If one of the strings have p distinct vowels, the other will contain the missing 5-p vowels from the vowel set, v = {a, e, i, o, u}

Both of them will be of same length.

Sample Input

Output

S1: national

S2: umbrella

Twin String

S1: education

S2: notorious

Twin String

S1: bangladesh

S2: pakistan

Not Twin String

Sample Output
S1: national
S2: umbrella

Twin String


Process returned 0 (0x0)   execution time : 23.699 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int i, j, k = 0, length1, length2, vowel = 0, a = 0, e = 0, iV = 0, o = 0, u = 0;
    char s1[30], s2[30];
 
    printf("S1: ");
    gets(s1);
 
    printf("S2: ");
    gets(s2);
 
    for(i = 0; s1[i] != '\0'; i++);
    length1 = i;
 
    for(i = 0; s2[i] != '\0'; i++);
    length2 = i;
 
    if(length1 == length2)
    {
        for(i = 0; i < length1; i++)
        {
            if(s1[i] == 'a' && a == 0)
            {
                a = 1;
                vowel++;
            }
            else if(s1[i] == 'e' && e == 0)
            {
                e = 1;
                vowel++;
            }
            else if(s1[i] == 'i' && iV == 0)
            {
                iV = 1;
                vowel++;
            }
            else if(s1[i] == 'o' && o == 0)
            {
                o = 1;
                vowel++;
            }
            else if(s1[i] == 'u' && u == 0)
            {
                u = 1;
                vowel++;
            }
            if(s2[i] == 'a' && a == 0)
            {
                a = 1;
                vowel++;
            }
            else if(s2[i] == 'e' && e == 0)
            {
                e = 1;
                vowel++;
            }
            else if(s2[i] == 'i' && iV == 0)
            {
                iV = 1;
                vowel++;
            }
            else if(s2[i] == 'o' && o == 0)
            {
                o = 1;
                vowel++;
            }
            else if(s2[i] == 'u' && u == 0)
            {
                u = 1;
                vowel++;
            }
        }
    }
 
    if(vowel == 5)
    {
        printf("\nTwin String");
    }
    else
    {
        printf("\nNot Twin String");
    }
    printf("\n\n");
    
    return 0;
}
Sample Output-1
S1: bangladesh
S2: pakistan

Not Twin String


Process returned 0 (0x0)   execution time : 11.287 s
Press any key to continue.
Sample Output-2
S1: abaca
S2: acada

Not Twin String


Process returned 0 (0x0)   execution time : 10.481 s
Press any key to continue.

No comments:

Post a Comment

Change Theme
X