commit
This commit is contained in:
parent
a5e30acb49
commit
02723374df
48
a2/program.c
Normal file
48
a2/program.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int is_vowel(char c) {
|
||||
c = tolower(c);
|
||||
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
|
||||
}
|
||||
|
||||
void to_pig_latin(char *word) {
|
||||
int len = strlen(word);
|
||||
char lower[100];
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
lower[i] = tolower(word[i]);
|
||||
lower[len] = '\0';
|
||||
|
||||
if (is_vowel(word[0]) ||
|
||||
(lower[0] == 'x' && lower[1] == 'r') ||
|
||||
(lower[0] == 'y' && lower[1] == 't')) {
|
||||
printf("%say\n", word);
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (i < len && !is_vowel(lower[i])) {
|
||||
if (lower[i] == 'q' && lower[i+1] == 'u') {
|
||||
i += 2;
|
||||
break;
|
||||
}
|
||||
if (lower[i+1] == 'y') {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
for (int j = i; j < len; j++) printf("%c", word[j]);
|
||||
for (int j = 0; j < i; j++) printf("%c", word[j]);
|
||||
printf("ay\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
char word[100];
|
||||
printf("Zadaj slovo: ");
|
||||
scanf("%s", word);
|
||||
to_pig_latin(word);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user