Bài 4.2. Tìm số đẹp


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 674M

Author:
Problem type

Số đẹp được định nghĩa là số mà trong đó số lượng chữ số chẵn và lẻ của n là bằng nhau. Nhập vào một số nguyên dương n (0<=n<=10^18). Nếu số nhập vào là số đẹp, thì in ra "YES", trường hợp ngược lại in ra "NO".

Ví Dụ

Input

111222

Output

YES

Input

122122

Output

NO

Comments


  • 0
    EchVaVit  commented on May 1, 2025, 10:29 a.m.

    .lua

    local input = io.read() 
    
    local num_of_odd = 0
    local num_of_even = 0
    
    
    for i = 1, #input do
        local char = string.sub(input, i, i) 
        local curr_num = tonumber(char)
        if curr_num % 2 == 0 then
            num_of_even = num_of_even + 1
        else
            num_of_odd = num_of_odd + 1
        end
    
    end
    
    if num_of_even == num_of_odd then
        io.write("YES")
    else
        io.write("NO")
    end