UVA Problem 11713 – Abstract Names Solution

UVA Problem 11713 – Abstract Names Solution:


Click here to go to this problem in uva Online Judge.

Solving Technique:

For input of n there will be 2*n lines. Task is to match a pair of lines. The vowels a, e, i, o, u in the strings doesn’t matter. Except these the rest of both strings should match.

That means each character in a index from both strings should match. Their order needs to be same. Except vowels if the match then output is yes. Otherwise the output is no.

 

Important:  Be sure to add or print a new line after each output unless otherwise specified. The outputs should match exactly because sometimes even a space character causes the answer to be marked as wrong answer. Please compile with c++ compiler as some of my codes are in c and some in c++.


More Inputs of This Problem on uDebug.


Input:

5
pele
polo
pele
pola
ronaldo
ronaldino
pele
pelet
pele
bele

 


Output:

Yes
Yes
No
No
No

Code:

/**
 * Author:    Asif Ahmed
 * Site:      https://quickgrid.wordpress.com
 * Problem:   UVA 11713 - Abstract Names
 * Technique: Removing specific characters from string
 *            by copying into another string.
 */

#include<stdio.h>
#include<string.h>

#define N 36


static char s[N];
static char t[N];

static char tmpS[N];
static char tmpT[N];


int main(){

    int n;

    scanf("%d", &n);
    getchar();

    while( n-- ){


        gets(s);
        gets(t);


        // If their length is not the same then output is no.
        if( strlen(s) != strlen(t) ){
            printf("No\n");
            continue;
        }


        // Reset memory.
        int j = 0, k = 0;
        memset(tmpS, 0, sizeof tmpS);
        memset(tmpT, 0, sizeof tmpT);


        // Remove vowels from the first string.
        for(int i = 0; s[i]; ++i){
            if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u')
                continue;
            else
                tmpS[j++] = s[i];
        }


        // Remove vowels from the second the string.
        for(int i = 0; t[i]; ++i){
            if(t[i] == 'a' || t[i] == 'e' || t[i] == 'i' || t[i] == 'o' || t[i] == 'u')
                continue;
            else
                tmpT[k++] = t[i];
        }


        // After removing the vowels the strings should match.
        if( strcmp(tmpS, tmpT) == 0 )
            printf("Yes\n");
        else
            printf("No\n");

    }

    return 0;
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s