345
This commit is contained in:
32
src/345.c
Normal file
32
src/345.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <solution/345.h>
|
||||
#include <string.h>
|
||||
|
||||
#define equal(x) \
|
||||
((x) == 'a' || (x) == 'A' || (x) == 'e' || (x) == 'E' || (x) == 'i' || (x) == 'I' || (x) == 'o' || (x) == 'O' || \
|
||||
(x) == 'u' || (x) == 'U')
|
||||
|
||||
#define swap(x, y, cb) \
|
||||
do \
|
||||
{ \
|
||||
char t = x; \
|
||||
x = y; \
|
||||
y = t; \
|
||||
cb; \
|
||||
} while (0)
|
||||
|
||||
char *reverseVowels(char *s)
|
||||
{
|
||||
for (int i = 0, j = strlen(s) - 1, f = 1; i < j;)
|
||||
{
|
||||
if (f && equal(s[i]))
|
||||
f = 0;
|
||||
else if (f)
|
||||
i++;
|
||||
else if (!f && equal(s[j]))
|
||||
swap(s[i], s[j], (f = 1, i++, j--));
|
||||
else
|
||||
j--;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user