Π—Π°Π΄Π°Ρ‡Π°: Π£ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ кошки Π΅ΡΡ‚ΡŒ имя ΠΈ кошка-ΠΌΠ°ΠΌΠ°. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ класс, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π±Ρ‹ описывал Π΄Π°Π½Π½ΡƒΡŽ ΡΠΈΡ‚ΡƒΠ°Ρ†ΠΈΡŽ. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ Π΄Π²Π° ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Π°: ΠΊΠΎΡˆΠΊΡƒ-Π΄ΠΎΡ‡ΡŒ ΠΈ ΠΊΠΎΡˆΠΊΡƒ-ΠΌΠ°ΠΌΡƒ. ВывСсти ΠΈΡ… Π½Π° экран. Новая Π·Π°Π΄Π°Ρ‡Π°: Π£ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ кошки Π΅ΡΡ‚ΡŒ имя, кошка-ΠΏΠ°ΠΏΠ° ΠΈ кошка-ΠΌΠ°ΠΌΠ°. Π˜Π·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ класс Cat Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ ΠΌΠΎΠ³ ΠΎΠΏΠΈΡΠ°Ρ‚ΡŒ Π΄Π°Π½Π½ΡƒΡŽ ΡΠΈΡ‚ΡƒΠ°Ρ†ΠΈΡŽ. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ 6 ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ²: Π΄Π΅Π΄ΡƒΡˆΠΊΡƒ (ΠΏΠ°ΠΏΠΈΠ½ ΠΏΠ°ΠΏΠ°), Π±Π°Π±ΡƒΡˆΠΊΡƒ (ΠΌΠ°ΠΌΠΈΠ½Π° ΠΌΠ°ΠΌΠ°), ΠΏΠ°ΠΏΡƒ, ΠΌΠ°ΠΌΡƒ, сына, Π΄ΠΎΡ‡ΡŒ. ВывСсти ΠΈΡ… всСх Π½Π° экран Π² порядкС: Π΄Π΅Π΄ΡƒΡˆΠΊΠ°, Π±Π°Π±ΡƒΡˆΠΊΠ°, ΠΏΠ°ΠΏΠ°, ΠΌΠ°ΠΌΠ°, сын, Π΄ΠΎΡ‡ΡŒ. Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹:
Cat name is Π΄Π΅Π΄ΡƒΡˆΠΊΠ° Вася, no mother, no father
Cat name is Π±Π°Π±ΡƒΡˆΠΊΠ° ΠœΡƒΡ€ΠΊΠ°, no mother, no father
Cat name is ΠΏΠ°ΠΏΠ° ΠšΠΎΡ‚ΠΎΡ„Π΅ΠΉ, no mother, father is Π΄Π΅Π΄ΡƒΡˆΠΊΠ° Вася
Cat name is ΠΌΠ°ΠΌΠ° Василиса, no mother, father is Π±Π°Π±ΡƒΡˆΠΊΠ° ΠœΡƒΡ€ΠΊΠ°
Cat name is сын ΠœΡƒΡ€Ρ‡ΠΈΠΊ, mother is ΠΌΠ°ΠΌΠ° Василиса, father is ΠΏΠ°ΠΏΠ° ΠšΠΎΡ‚ΠΎΡ„Π΅ΠΉ
Cat name is Π΄ΠΎΡ‡ΡŒ ΠŸΡƒΡˆΠΈΠ½ΠΊΠ°, mother is ΠΌΠ°ΠΌΠ° Василиса, father is ΠΏΠ°ΠΏΠ° ΠšΠΎΡ‚ΠΎΡ„Π΅ΠΉ
public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String grandfatherName = reader.readLine();
        Cat catGrandfather = new Cat(grandfatherName);

        String grandmotherName = reader.readLine();
        Cat catGrandmother = new Cat(grandmotherName);

        String dadName = reader.readLine();
        Cat catDad = new Cat(dadName, catGrandfather);

        String motherName = reader.readLine();
        Cat catMother = new Cat(motherName, catGrandmother);

        String sonName = reader.readLine();
        Cat catSon = new Cat(sonName, catMother, catDad);

        String daughterName = reader.readLine();
        Cat catDaughter = new Cat(daughterName, catMother, catDad);

        System.out.println(catGrandfather);
        System.out.println(catGrandmother);
        System.out.println(catDad);
        System.out.println(catMother);
        System.out.println(catSon);
        System.out.println(catDaughter);}

    public static class Cat {
        private String name;
        private Cat parent, parent1;

        Cat(String name) {
           this.name = name;
        }

        Cat(String name, Cat parent) {
            this.name = name;
            this.parent = parent;
        }

        Cat(String name, Cat parent, Cat parent1) {
            this.name = name;
            this.parent = parent;
            this.parent1 = parent1;
        }

        @Override
        public String toString() {
            if (parent == null && parent1 == null)
                return "Cat name is " + name + ", no mother, no father";

            if (parent1 == null)
                return "Cat name is " + name + ", no mother, father is " + parent.name;

            if (parent == null)
                return "Cat name is " + name + ", mother is " + parent1.name + ", no father" ;

           else
                return "Cat name is " + name + ", mother is " + parent.name + ", father is " + parent1.name;
        }
    }
}