Search This Blog

Techgig Geek Goddess Screening Round Solution - Python

 



Oddia and Evenia are two friends who love strings and prime numbers. Although they have the same taste and like similar things, they are enemies when it comes to even and odd numbers. Oddia likes the odd numbers and Evenia likes the even numbers. They have a problem for you to solve.

A string S of lowercase letters will be provided and you have to figure out if the given string is Prime String or not. The index starts at 1.

Prime String: A string is considered a prime string only if the absolute difference between the sum of odd indexed letters and even indexed letters is completely divisible by any of the odd prime numbers less than 10.

Note: For calculations, consider the ASCII value of lowercase letters.

Example:

String, S = abcdef

Summation of Odd Indexed letters, O = a + c + e = 97 + 99 + 101 = 297

Summation of Even Indexed letters, E = b + d + f = 98 + 100 + 102 = 300

Absolute Difference = |O-E| = |297-300| = 3

This is completely divisible by 3 and leaves 0 as remainder. Thus, the given string is a Prime String.

If the string is prime string, print Prime String otherwise print Causal String. Can you solve it?


Input Format

The first line of input consists of the number of test cases, T

Next N lines each consist of a string, S.

Note: Read the input from the console.

Constraints

1<= T <=10

2<= |S| <=10000

|S| is the length of the string.


Output Format

For each test case, print Prime String if the string is prime string otherwise print Casual String.


Sample TestCase 1

Input

2

bbae

abcdef

Output

Casual String

Prime String

Explanation

Test Case 1: 


Sum of Odd indexed letters, O = 98+97 = 195

Sum of Even indexed letters, E = 98 + 101 = 199

Absolute Difference = |195-199| = 4

This is not divisible by any of the odd prime numbers. The given string is a Casual String.

----------------------------------------

Solution:

def check():

    
    num = int(input())

 

    for i in range(num):
        st = input()
        i = 0
        even_num = 0
        odd_num = 0
        for char in st:
            if i % 2 == 0:
                even_num+=ord(char)
            else:
                odd_num+=ord(char)
            i+=1
            
        ab_diff = abs(even-odd)
    
        if ab_diff % 3 == 0 or ab_diff % 5 == 0 or ab_diff % 7 == 0:
            print("Prime String")
        else:
            print("Casual String")

check()



No comments:

Post a Comment