美文网首页
118A - String Task

118A - String Task

作者: passwd_ | 来源:发表于2017-07-06 18:55 被阅读0次

    Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:

    deletes all the vowels,
    inserts a character "." before each consonant,
    replaces all uppercase consonants with corresponding lowercase ones.
    Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.

    Help Petya cope with this easy task.
    Input
    The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
    Output
    Print the resulting string. It is guaranteed that this string is not empty.
    Example
    Input
    tour
    Output
    .t.r
    Input
    Codeforces
    Output
    .c.d.f.r.c.s
    Input
    aBAcAba
    Output
    .b.c.b
    题目大意:给定一个字符串,不显示其中的元音字母,辅音字母前面加'.'输出

    #include <stdio.h>
    #include <string.h>
    #define MAX 100
    
    int main()
    {
    
        char str[MAX];
        int len,i=0;
        //printf("Input\n");
        scanf("%s",str);
        //printf("Output\n");
        for (int i = 0; str[i]!='\0'; i++){
            if (str[i]>='A'&&str[i]<='Z')
            {
                str[i]=str[i]+32; //大小写转换
    
            }
            if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='y')
            {
                str[i]=-1; //这里做一个假删除
            }
            if (str[i]!=-1)
            {
                printf(".");
                printf("%c",str[i]);
            }
    
        }
    
        printf("\n");
        return 0;
    
    }
    

    其中两行print是不需要的,加上通过不了。所以注释掉了

    相关文章

      网友评论

          本文标题:118A - String Task

          本文链接:https://www.haomeiwen.com/subject/dackhxtx.html