Extra Krunch

来源:互联网 发布:我为什么离开华为 知乎 编辑:程序博客网 时间:2024/05/20 11:34

Extra Krunch

Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 4794 Accepted: 1180

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.
 
http://poj.org/problem?id=1951
 
简单的字符串操作练习,利用了c++中string类的特性解决的问题。
 
#include <iostream>#include <cstdio>#include <string>using namespace std;int main(){string s1,s2,s3;int num,i;getline(cin,s1);num=s1.size();for (i=0;i<num;i++){if(s1[i]!='A'&&s1[i]!='E'&&s1[i]!='I'&&s1[i]!='O'&&s1[i]!='U'){if (s2.find(s1[i])==string::npos){if (s3.empty()){if (s1[i]==' ')continue;elses3+=s1[i];}else{if (s3[s3.size()-1]==' '&&(s1[i]==','||s1[i]=='.'||s1[i]=='?'))s3[s3.size()-1]=s1[i];else if (!(s3[s3.size()-1]==' '&&s3[s3.size()-1]==s1[i]))s3+=s1[i];}if (!(s1[i]==' '||s1[i]==','||s1[i]=='.'||s1[i]=='?'))s2+=s1[i];}}}if (s3.size()>0){while(s3.size()>0){    string::iterator iter1=s3.end();--iter1;if(*iter1==' ')s3.erase(iter1);elsebreak;}}cout<<s3<<endl;return 0;}