Given a string s
, remove the vowels 'a'
, 'e'
, 'i'
, 'o'
, and 'u'
from it, and return the new string.
Example 1:
Input: s = "leetcodeisacommunityforcoders " Output: "ltcdscmmntyfrcdrs "
Example 2:
Input: s = "aeiou " Output: " "
Constraints:
1 <= s.length <= 1000
s
consists of only lowercase English letters.program main
implicit none
character(len=1000) :: s
character(len=1000) :: result
! Example 1
s = "leetcodeisacommunityforcoders"
write(*,"(A)") trim(remove_vowels(s))
! Example 2
s = "aeiou "
write(*,"(A)") trim(remove_vowels(s))
contains
function remove_vowels(str) result(new_str)
implicit none
character(len=*), intent(in) :: str
character(len=len(str)) :: new_str
integer :: i, j
do i = 1, len(str)
if (str(i:i) /= 'a' .and. &
str(i:i) /= 'e' .and. &
str(i:i) /= 'i' .and. &
str(i:i) /= 'o' .and. &
str(i:i) /= 'u') then
new_str(j:j) = str(i:i)
j = j + 1
end if
end do
end function remove_vowels
end program main
Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7ae45a9a6960 in ??? #1 0x7ae45a9a5ac5 in ??? #2 0x7ae45a79c51f in ??? #3 0x57ddae1562ad in remove_vowels.0 #4 0x57ddae1563de in MAIN__ #5 0x57ddae1565d3 in main
! Declare the input string and the output string
character(len=1000) :: s, output
! Declare the vowels to be removed
character(len=5) :: vowels = "aeiou"
! Declare the length of the input string
integer :: len_s
! Get the length of the input string
len_s = len_trim(s)
! Initialize the output string
output = ""
! Loop through each character in the input string
do i = 1, len_s
! If the current character is not a vowel, add it to the output string
if (index(vowels, s(i:i)) == 0) then
output = output // s(i:i)
endif
enddo
! Print the output string to stdout
write (*,*) output
end
def is_robot_bounded(instructions: str) -> bool:
x, y, dir = 0, 0, 0
moves = [(0, 1), (1, 0), (0, -1), (-1, 0)]
for c in instructions:
if c == 'G':
x += moves[dir][0]
y += moves[dir][1]
elif c == 'L':
dir = (dir + 3) % 4
else:
dir = (dir + 1) % 4
return (x == 0 and y == 0) or dir != 0
bool isRobotBounded(string instructions) {
int x = 0, y = 0, dir = 0;
vector<vector<int>> moves {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
for (char c : instructions) {
if (c == 'G') {
x += moves[dir][0];
y += moves[dir][1];
} else if (c == 'L') {
dir = (dir + 3) % 4;
} else {
dir = (dir + 1) % 4;
}
}
return (x == 0 && y == 0) || dir != 0;
}