Techgig

Prime String

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.


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 Casual 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.


#JAVA

import java.util.Scanner;

class CandidateCode {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
char[] chr = sc.next().toCharArray();
int k = 0;
int even = 0;
int odd = 0;
for (char c : chr) {
if (k % 2 == 0) even += c;
else odd += c;
k += 1;
}
int diff = Math.abs(odd - even);
if (diff % 3 == 0 || diff % 5 == 0 || diff % 7 == 0) System.out.println("Prime String");
else System.out.println("Casual String");
}
}
}
#GO
package main

import (
"fmt"
)
func main() {
var n int
_, _ = fmt.Scanln(&n)
for i := 0; i < n; i++ {
var s string
var even int32 = 0
var odd int32 = 0
_, _ = fmt.Scanln(&s)
for k, r := range s {
if k % 2 == 0 {
even += r
}else {
odd += r
}
}
diff := Abs(odd-even)
if diff % 3 == 0 || diff % 5 == 0 || diff % 7 == 0 {
fmt.Println("Prime String")
} else {
fmt.Println("Casual String")
}
}
}
func Abs(x int32) int32 {
if x < 0 {
return -x
}
return x
}

#Python
n = int(input())
for i in range(n):
s = input()
i = 0
even = 0
odd = 0
for char in s:
if i % 2 == 0:
even+=ord(char)
else:
odd+=ord(char)
i+=1
diff = abs(even-odd)
if diff % 3 == 0 or diff % 5 == 0 or diff % 7 == 0:
print("Prime String")
else:
print("Casual String")

#C++
#include <iostream>
using namespace std;
#include <iostream>
#include <cstring>
#include <cstdlib>

int main() {
int n;
string s;
cin>>n;
for (int i = 0; i < n; i++) {
cin >> s;
char chr[s.length() + 1];
strcpy(chr, s.c_str());
int k = 0;
int even = 0;
int odd = 0;
for (char c : chr) {
if (k % 2 == 0) even += c;
else odd += c;
k += 1;
}
int diff = labs(odd - even);
if (diff % 3 == 0 || diff % 5 == 0 || diff % 7 == 0)
cout << "Prime String" << endl;
else cout << "Casual String" << endl;
}
return 0;
}