Algorithm
Problem Link in UVA Online Judge - https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=433
Online Judge Name - UVA Online Judge
Volume - 4
Problem Details:
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.
Code Examples
#1 Code Example with C Programming Example #1
Code -
C Programming
#include <stdio.h>
char s;
char stack[1000000];
int main() {
int idx = 0;
while(s = getchar()) {
if(s == EOF)
break;
switch(s) {
case 'a' ... 'z':
stack[idx++] = s;
break;
case 'A' ... 'Z':
stack[idx++] = s;
break;
default:
if(idx > 0) {
stack[idx] = '\0';
switch(stack[0]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%say", stack);
break;
default:
printf("%s%cay", stack+1, stack[0]);
}
idx = 0;
}
putchar(s);
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C Programming - Example #2
Code -
C Programming
#include <stdio.h>
int main()
{
int a,b,c,d,flag;
char g,v;
while((g=getchar())!=EOF)
{
if((g < 'a'||g>'z') &&(g<'A'||g>'Z'))
printf("%c",g);
else if(g=='a'||g=='A'||g=='e'||g=='E'||g=='i'||g=='I'||g=='o'||g=='O'||g=='u'||g=='U')
{
printf("%c",g);
while((g=getchar())&&(g>='a'&&g<='z'>||(g>='A'&&g < ='Z'))
printf("%c",g);
printf("ay%c",g);
}
else if((g>='a'&&g<='z'>||(g>='A'&&g < ='Z'))
{
v=g;
while((g=getchar())&&(g>='a'&&g<='z')||(g>='A'&&g<='Z'))
printf("%c",g);
printf("%cay%c",v,g);
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
Demonstration
#492 - UVA Online Judge solution Pig Latine - 492 - Pig-Latin - Solution in C, C++, Java, PHP, Python, C#