本文主要是介绍POJ - 1951,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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.
一道模拟题给我搞蒙了米有看到还有,和?而且后来才知道只要判断,?。之前有没有“space”有就覆盖没有就直接放而且题目描述的规则只适用于大写字母。然后扫一遍就行了
#include <iostream>
#include <cmath>
#include<set>
#include <algorithm>
#include<string>
#include<string.h>
using namespace std;
int main()
{string s;char ss[10000];int n,m,a,b[1000];while(getline(cin,s)){memset(b,0,sizeof(b));b['A']=1,b['U']=1,b['O']=1,b['I']=1,b['E']=1;a=s.size();int i,j;for(i=0,j=0; i<a; i++){if(isupper(s[i])){if(!b[s[i]]){ss[j++]=s[i];b[s[i]]=1;}}else if(s[i]==','||s[i]=='?'||s[i]=='.'){if(ss[j-1]==' ')ss[j-1]=s[i];elsess[j++]=s[i];}else if(ss[j-1]!=' '&&j!=0){if(s[i]==' ')ss[j++]=s[i];}}for(int i=0;i<j;i++)cout<<ss[i];cout<<endl;}
}
这篇关于POJ - 1951的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!