Extra Krunch

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值