2013年2月28日 星期四

ACM 11713 Abstract Names

"Two names are considered same if they are of same length and they only vary at positions where vowels occur." 但是其實兩個names如果長的一模一樣,也算是same (有點廢話...但我一開始寫的時候以為不算same...有夠白癡= =)

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

int is_vowel(char c)
{
    if (c == 'a' || c == 'e' || c == 'i' ||
        c == 'o' || c == 'u')
        return 1;
    return 0;
}

int main(void)
{
    int i, n, len1, len2, flag;
    char s1[20+1], s2[20+1];

    scanf("%d ", &n);
    while (n--) {
        gets(s1);
        gets(s2);

        len1 = strlen(s1);
        len2 = strlen(s2);

        if (len1 != len2) {
            printf("No\n");
            continue;
        }

        flag = 1;
        for (i = 0; i < len1; ++i)
            if (s1[i] != s2[i]) {
                if (is_vowel(s1[i]) && is_vowel(s2[i]))
                    flag = 1;
                else {
                    flag = 0;
                    break;
                }
            }

        if (flag)
            printf("Yes\n");
        else
            printf("No\n");
    }

    return 0;
}

沒有留言:

張貼留言