// CCC2006s1Maternity // // given a mothers and fathers genes, determine if a baby may // be theirs. (dominant/recessive gene ideas) // // Basic string handling and basic structures import java.io.*; // supports RandomAccessFile & PrintWriter import java.util.Scanner; // supports input with Scanner class public class CCC2006s1Maternity { public static void main (String[] args) throws IOException { // ======== Open channels to input and output files. ============ Scanner in = new Scanner (new File("s1.3.in")); PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter("s1.3.out"))); String baby; String mother = in.next(); String father = in.next(); int x = in.nextInt() ; for (int i = 1 ; i <= x ; i++) { baby = in.next(); if (possibleBaby (mother, father, baby)) out.println ("Possible baby."); else out.println ("Not their baby!"); } out.close(); // really important to flush data to disk's file! } // end main() // if baby has Capital, one parent needs to have one Capital // if baby has lower, both parents need a lower public static boolean possibleBaby (String m, String f, String b) { boolean okay = true; for (int i = 0 ; i <= 4 && okay ; i++) if (b.charAt (i) >= 'A' && b.charAt (i) <= 'E') okay = (m.charAt (i * 2) >= 'A' && m.charAt (i * 2) <= 'E') || (m.charAt (i * 2 + 1) >= 'A' && m.charAt (i * 2 + 1) <= 'E') || (f.charAt (i * 2) >= 'A' && f.charAt (i * 2) <= 'E') || (f.charAt (i * 2 + 1) >= 'A' && f.charAt (i * 2 + 1) <= 'E'); else okay = ((m.charAt (i * 2) >= 'a' && m.charAt (i * 2) <= 'e') || (m.charAt (i * 2 + 1) >= 'a' && m.charAt (i * 2 + 1) <= 'e')) && ((f.charAt (i * 2) >= 'a' && f.charAt (i * 2) <= 'e') || (f.charAt (i * 2 + 1) >= 'a' && f.charAt (i * 2 + 1) <= 'e')); return okay; } }