Extra Krunch

来源:互联网 发布:四川理工学院网络教学 编辑:程序博客网 时间:2024/05/20 06:38

Description

A krunched word has no vowels ("A", "E", "I", "O", and "U") and no repeated letters. Removing vowels and letters that appear twice or more from MISSISSIPPI yields MSP. In a krunched word, a letter appears only once, the first time it would appear in the unkrunched word. Vowels never appear. 

Krunched phrases similarly have no vowels and no repeated letters. Consider this phrase: 
        RAILROAD CROSSING

and its krunched version: 
        RLD CSNG

Blanks are krunched differently. Blanks are removed so that a krunched phrase has no blanks on its beginning or end, never has two blanks in a row, and has no blanks before punctuation. Otherwise, blanks not removed. If we represent blanks by "_", 
        MADAM_I_SAY_I_AM_ADAM__

krunches to: 
        MD_SY

where the single remaining blank is shown by "_". 

Write a program that reads a line of input (whose length ranges from 2 to 70 characters), and krunches it. Put the krunched word or phrase in the output file. The input line has only capital letters, blanks, and the standard punctuation marks: period, comma, and question mark.

Input

A single line to be krunched. 

Output

A single krunched line that follows the rules above. 

题意:给出一个只含大写字母,空格 ,逗号,句号,问号的字符串,最后输出的字符串首尾不能有空格,不能有连续的空格,不能有元音字母,字母只能出现一次,标点符号前面不可以空格

Sample Input

NOW IS THE TIME FOR ALL GOOD MEN TO COME TO THE AID OF THEIR COUNTRY.

Sample Output

NW S TH M FR L GD C Y.

#include<iostream>#include<algorithm>#include<string>#include<cstdio>#include<cstring>using namespace std;int main(){    bool vis[26];    char ch[75],res[75];    int i,cnt;    while(gets(ch))    {        cnt=0;        memset(vis,0,sizeof(vis));        vis['A'-'A']=true;        vis['E'-'A']=true;        vis['I'-'A']=true;        vis['O'-'A']=true;        vis['U'-'A']=true;        for(int i=0;ch[i]!='\0';i++)        {            if(isalpha(ch[i]))            {                if(!vis[ch[i]-'A'])                {                    res[cnt++]=ch[i];                    vis[ch[i]-'A']=true;                }            }            else if(ch[i]==','||ch[i]=='.'||ch[i]=='?')            {                if(res[cnt-1]==' ')                    res[cnt-1]=ch[i];                else                    res[cnt++]=ch[i];            }            else if(res[cnt-1]!=' '&&cnt!=0)            {                if(ch[i]==' ')                {                    res[cnt++]=ch[i];                }            }        }        res[cnt]='\0';        printf("%s\n",res);    }    return 0;}


0 0
原创粉丝点击