BNUOJ 14280 Extra Krunch

USACO 2002 February的一道题。

注意两点:

        1.结果的开头和结尾没有空格;

        2.标点前面没有空格;

这题怒送6PE...

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int i,f,la;
    char str[80];
    char ans[80];
    bool ck[26];
    memset(ck,false,sizeof(ck));
    f=0;
    la=0;
    gets(str);
        for (i=0; str[i]; i++)
        {
            if (str[i] <= 'Z' && str[i] >= 'A')
            {
                if (str[i] == 'A' || str[i] == 'E' || str[i] == 'I'
                 || str[i] == 'O' || str[i] == 'U' || ck[str[i]-'A'] == true)
                {
                    continue;
                }
                f=0;
                ans[la++]=str[i];
                ck[str[i]-'A']=true;
            }
            else
            {
                if (str[i] == ' ' && f == 0)
                {
                    f=1;
                    ans[la++]=str[i];
                }
                else
                {
                    if (str[i] != ' ')
                    {
                        if (ans[la-1] == ' ')
                            la--;
                        ans[la++]=str[i];
                    }
                }
            }
        }
    while (ans[la-1] == ' ')
        la--;
    ans[la]='\0';
    for (i=0; ans[i]; i++)
    {
        if (ans[i] != ' ')
            break;
    }
    for (; ans[i]; i++)
    {
        printf("%c",ans[i]);
    }
    printf("\n");
    return 0;
}


你可能感兴趣的:(BNUOJ 14280 Extra Krunch)