当前位置:网站首页>Pig-Latin (UVA492)
Pig-Latin (UVA492)
2022-06-30 03:55:00 【Cod_ ing】
You have decided that PGP encryptation is not strong enough for your
email. You have decided to supplement it by first converting your
clear text letter into Pig Latin before encrypting it with PGP.
Input and Output
You are to write a program that will take in an arbitrary number of
lines of text and output it in Pig Latin. Each line of text will
contain one or more words. A “word” is defined as a consecutive
sequence of letters (upper and/or lower case). Words should be
converted to Pig Latin according to the following rules (non-words
should be output exactly as they appear in the input):
- Words that begin with a vowel (a, e, i, o, or u, and the capital versions of these) should just have the string “ay” (not including the
quotes) appended to it. For example, “apple” becomes “appleay”.- Words that begin with a consonant (any letter than is not A, a, E, e, I, i, O, o, U or u) should have the first consonant removed and
appended to the end of the word, and then appending “ay” as well. For
example, “hello” becomes “ellohay”.- Do not change the case of any letter.
Sample Input
This is the input.
Sample Output
hisTay isay hetay inputay.
/* General idea : Judge the input string character by character ; */
#include<iostream>
#include<string>
using namespace std;
// Decide if it's a letter
int isab(char ch){
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
return 1;
else
return 0;
}
// Determine if it's a vowel
int vowel(char ch){
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'
||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
return 1;
else
return 0;
}
int main(){
string str;
getline(cin,str);
char temp;
int flag=0; //flag Used to mark whether a character is within a word
for(int i=0;i<str.size();i++){
// This character is not a letter , but flag==1, Explain that a word is over .
if(!isab(str[i])&&flag==1){
if(isab(temp))
cout<<temp;
cout<<"ay";
cout<<str[i];
temp='@';
flag=0;
}
// Other characters not next to words , Then output directly
else if(!isab(str[i]))
cout<<str[i];
//flag==0, It's a vowel letter , It is a word that begins with a vowel
else if(vowel(str[i])&&flag==0){
cout<<str[i];
flag=1;
}
// Empathy , But consonants begin , Deposit first temp, Output the rest of the characters of the whole word after it is finished ( The first 31 That's ok )
else if(!vowel(str[i])&&flag==0){
temp=str[i];
flag=1;
}
// The characters inside the word can be output directly
else
cout<<str[i];
}
cout<<endl;
}
边栏推荐
- Semantic segmentation resources
- About manipulator on Intelligent Vision Group
- Interpretation score of bilstm-crf in NER_ sentence
- NER中BiLSTM-CRF解读score_sentence
- [operation] MySQL query operation 2 on May 25, 2022
- Selenium environment installation, 8 elements positioning --01
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- 【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
- 尝试链接数据库时出现链接超时报错,如何解决?
- Interface test tool postman
猜你喜欢

Linear interpolation of spectral response function

(Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces

Day 9 script and resource management

【图像融合】基于交叉双边滤波器和加权平均实现多焦点和多光谱图像融合附matlab代码

Chapter 2 control structure and function (programming problem)

I have published a book, "changing life against the sky - the way for programmers to become gods", which is open source. I have been working for ten years. There are 100 life suggestions from technica

DBT product initial experience

第九天 脚本与资源管理

Solve the problem of Navicat connecting to the database

绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中
随机推荐
深入浅出掌握grpc通信框架
Magical Union
DO280私有仓库持久存储与章节实验
Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
How to use FME to create your own functional software
毕业设计EMS办公管理系统(B/S结构)+J2EE+SQLserver8.0
Use ideal to connect to the database. The results show some warnings. How to deal with this part
[punch in - Blue Bridge Cup] day 1 --% 7F format output
The 5-year Android development interview took 20 days to join Alibaba
【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)
Radiant energy, irradiance and radiance
Practical debugging skills
如何通过进程启动来分析和解决EasyCVR内核端口报错问题?
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
Jour 9 Gestion des scripts et des ressources
Feign pit
【个人总结】学习计划
[punch in - Blue Bridge Cup] day 3 --- slice in reverse order list[: -1]
[operation] MySQL query on May 24, 2022
Smart use of bitmap to achieve 100 million level massive data statistics