题目描述

字符串处理问题,也很简单
需要注意字符串的读取 用C语言getchar读取一直不对。。。。
#include<iostream>
#include<string>
#include<set>
using namespace std;
bool vow(char x)
{
x=toupper(x);
if(x=='A'||x=='E'||x=='I'||x=='O'||x=='U')return 1;
return 0;
}
int main(){
string s;
string temp="";
while(getline(cin,s)){
int i=0;
while(i<s.size())
{
if(isalpha(s[i]))
{
bool flag=1;
char fir;
if(vow(s[i])) flag=0;
else fir=s[i++];
while(isalpha(s[i]))
cout<<s[i++];
if(flag)
cout<<fir;
cout<<"ay";
}
else{
cout<<s[i++];
}
}
cout<<endl;
}
return 0;
}
本文介绍了一个简单的字符串处理问题,实现了 Pig Latin 的转换算法。该算法将英语句子中每个单词的辅音移到单词末尾并加上“ay”,如果单词以元音开头,则直接在末尾加“ay”。文章提供了 C++ 实现代码,并注意到了使用 getline 读取字符串的重要性。
927

被折叠的 条评论
为什么被折叠?



