Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Odd Odds Even Evens
- A number is called magical if the number of odd numbers in it is odd and the number of even numbers in it is even.
- Now, given a number, you have to help figure out if that number is magical or not. If it is, print "YES", otherwise print "NO".
- Input format:
- The first line contains
- T
- T, denoting the number of test cases.
- Each of the following T lines contain one number.
- Output format:
- Your output should be "YES" or "NO" according to the above mentioned conditions.
- --------------------------------------------------
- SWIFT 3.0
- --------------------------------------------------
- func digits(_ number: Int) -> [Int] {
- var number = number
- var digits: [Int] = []
- while number > 0 {
- digits.insert(number % 10, at: 0)
- number /= 10
- }
- return digits
- }
- var test_cases:Int = Int(readLine()!)!
- var answer_array = [Int]()
- var even_array = [Int]()
- var odd_array = [Int]()
- var allNumber_array = [Int]()
- for item in 1...test_cases {
- let num = Int(readLine()!)!
- allNumber_array = digits(num)
- for (index, item) in allNumber_array.enumerated()
- {
- if(item%2 == 0){
- even_array.append(item)
- } else {
- odd_array.append(item)
- }
- }
- if(even_array.count%2==0 && odd_array.count%2 == 1){
- print("YES")
- }else{
- print("NO")
- }
- even_array.removeAll()
- odd_array.removeAll()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement