A password is said to be strong if it satisfies all the following criteria:
8
characters."!@#$%^&*()-+ "
.2
of the same character in adjacent positions (i.e., "aab "
violates this condition, but "aba "
does not).Given a string password
, return true
if it is a strong password. Otherwise, return false
.
Example 1:
Input: password = "IloveLe3tcode! " Output: true Explanation: The password meets all the requirements. Therefore, we return true.
Example 2:
Input: password = "Me+You--IsMyDream " Output: false Explanation: The password does not contain a digit and also contains 2 of the same character in adjacent positions. Therefore, we return false.
Example 3:
Input: password = "1aB! " Output: false Explanation: The password does not meet the length requirement. Therefore, we return false.
Constraints:
1 <= password.length <= 100
password
consists of letters, digits, and special characters: "!@#$%^&*()-+ "
.program main
implicit none
integer :: i
character(len=100) :: password
do i = 1, size(examples)
read(examples(i), *) password
write(*, '(L1)') is_strong_password(password)
end do
contains
function is_strong_password(password) result(is_strong)
implicit none
character(len=*), intent(in) :: password
logical :: is_strong
is_strong = len(password) >= 8 &
.and. index(password, 'abcdefghijklmnopqrstuvwxyz') /= 0 &
.and. index(password, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') /= 0 &
.and. index(password, '0123456789') /= 0 &
.and. index(password, '!@#$%^&*()-+ ') /= 0 &
.and. count(password == password(1:size(password)-1)) < 2
end function is_strong_password
end program main
character(len=100), parameter :: examples(3) = (/ '"IloveLe3tcode! "', &
'"Me+You--IsMyDream "', &
'"1aB! "' /)
temp.f95:29:70: 29 | character(len=100), parameter :: examples(3) = (/ '"IloveLe3tcode! "', & | 1 Error: Different CHARACTER lengths (17/20) in array constructor at (1) temp.f95:24:52: 24 | .and. count(password == password(1:size(password)-1)) < 2 | 1 Error: ‘array’ argument of ‘size’ intrinsic at (1) must be an array temp.f95:8:13: 8 | read(examples(i), *) password | 1 Error: Function ‘examples’ at (1) has no IMPLICIT type temp.f95:7:27: 7 | do i = 1, size(examples) | 1 Error: Symbol ‘examples’ at (1) has no IMPLICIT type
! Declare variables
integer :: i, j, len
character(len=*) :: password
! Initialize variables
len = len_trim(password)
! Check if password is at least 8 characters long
if (len < 8) then
write (*,*) "Password must be at least 8 characters long"
stop
end if
! Check if password contains at least one lowercase letter
do i = 1, len
if (password(i:i) >= 'a' .and. password(i:i) <= 'z') then
exit
end if
end do
if (i > len) then
write (*,*) "Password must contain at least one lowercase letter"
stop
end if
! Check if password contains at least one uppercase letter
do i = 1, len
if (password(i:i) >= 'A' .and. password(i:i) <= 'Z') then
exit
end if
end do
if (i > len) then
write (*,*) "Password must contain at least one uppercase letter"
stop
end if
! Check if password contains at least one digit
do i = 1, len
if (password(i:i) >= '0' .and. password(i:i) <= '9') then
exit
end if
end do
if (i > len) then
write (*,*) "Password must contain at least one digit"
stop
end if
! Check if password contains at least one special character
do i = 1, len
if (password(i:i) >= '!' .and. password(i:i) <= '~') then
exit
end if
end do
if (i > len) then
write (*,*) "Password must contain at least one special character"
stop
end if
! Check if password does not contain 2 of the same character in adjacent positions
do i = 1, len - 1
if (password(i:i) == password(i+1:i+1)) then
write (*,*) "Password cannot contain 2 of the same character in adjacent positions"
stop
end if
end do
! If we reach this point, the password is strong
write (*,*) "Password is strong"
end
temp.f95:3:28: 3 | character(len=*) :: password | 1 Error: Entity with assumed character length at (1) must be a dummy argument or a PARAMETER
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def merge_nodes_between_zeros(head: ListNode) -> ListNode:
dummy = ListNode(0)
dummy.next = head
prev = dummy
cur = head
while cur:
if cur.val == 0:
tmp_sum = 0
while cur.next and cur.next.val != 0:
tmp_sum += cur.next.val
cur = cur.next
prev.next = ListNode(tmp_sum)
prev = prev.next
cur = cur.next
return dummy.next
class ListNode {
public:
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
ListNode* mergeNodesBetweenZeros(ListNode* head) {
ListNode* dummy = new ListNode(0);
dummy->next = head;
ListNode* prev = dummy;
ListNode* cur = head;
while (cur) {
if (cur->val == 0) {
int tmp_sum = 0;
while (cur->next && cur->next->val != 0) {
tmp_sum += cur->next->val;
cur = cur->next;
}
prev->next = new ListNode(tmp_sum);
prev = prev->next;
cur = cur->next;
}
}
return dummy->next;
}