Find Pattern of Odd and Even Digits

Mathematics is not just about crunching complex numbers or solving intricate problems; it’s also about identifying patterns. Patterns are everywhere, from the nature around us to the very numbers we use daily. In this computational quest, you’ll embark on a journey to uncover the rhythm of numbers, specifically focusing on the dance between odd and even digits.

Your task is simple yet thought-provoking. Given a number, can you delineate its pattern of odd and even digits? For every odd digit, represent it with an ‘O’, and for every even digit, represent it with an ‘E’. This will help us visualize the intriguing interplay of odd and even numbers, offering a fresh perspective on the numbers we often take for granted.

Boundary Condition(s):
10 <= N <= 10^9 (Given number)

Input Format:
A single integer N, the number whose pattern you’re eager to discover.

Output Format:
A string of ‘O’s and ‘E’s, representing the odd and even digits of N, respectively.

Example Input/Output 1:
Input:
1290

Output:
OOEO

Explanation:
For the number 1290, the digits 1 and 9 are odd (hence ‘O’ for both) while 2 and 0 are even (thus ‘E’ for both). The pattern for 1290, therefore, becomes OOEO.

n = input().strip()
pattern = ''
for digit in n:
    if int(digit) % 2 == 0:
        pattern += 'E'
    else:
        pattern += 'O'
print(pattern)
#include<stdio.h>

int main() {
    char n[10];
    scanf("%s", n);
    for(int i = 0; n[i] != ''; i++) {
        if((n[i] - '0') % 2 == 0) {
            printf("E");
        } else {
            printf("O");
        }
    }
    return 0;
}
#include <iostream>
using namespace std;

int main() {
    string n;
    cin >> n;
    for(char digit : n) {
        if((digit - '0') % 2 == 0) {
            cout << 'E';
        } else {
            cout << 'O';
        }
    }
    return 0;
}
import java.util.Scanner;

public class OddEvenPattern {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        for(char digit : n.toCharArray()) {
            if((digit - '0') % 2 == 0) {
                System.out.print('E');
            } else {
                System.out.print('O');
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.