POJ 1951 (模拟)

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.

题意:

一个字符串不能出现AEIOU这几个元音字母,如果有两个连续的空格只输出一个,所有的

用一个长度为27的数组记录每个字母是否出现,然后对每种情况特判模拟。

AC代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
using namespace std;
int i,j,k,l;
int ans;
char a[80],b[80];
int cnt=0;
bool vis[27];
int main()
{
    memset(vis,0,sizeof(vis));
    cnt=0;
    gets(a);
    int len=strlen(a);
    for(int i=0; i<len; i++)
    {
        if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U')
        {
            continue;
        }
        if(!vis[a[i]-'A']&&a[i]!=' '&&a[i]!='.'&&a[i]!=',')
        {
            b[cnt++]=a[i];
            vis[a[i]-'A']=1;
        }
        if(a[i]==' '||a[i]=='.'||a[i]==',')
        {
            b[cnt++]=a[i];
        }
    }
    for(int i=0;i<cnt;i++)
    {
        if(b[i]==' '&&b[i-1]==' ')
            continue;
        if(i==0&&b[0]==' ')
        continue;
        if(b[i]==' '&&b[i+1]=='.')
        continue;
        printf("%c",b[i]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值