Animal Sanctuary
+ Нов въпрос
Vesolini avatar Vesolini 6 Точки

1.Animal Sanctuary - Fundamentals Retake Final Exam - 18 April 2018


Опитвам се да реша по-долната задача, която се е падала на предишни изпити. Моето решение е без използването на Regex и съответно се мъча да разбера защо Judge ми дава 90/100. Най-вероятно изпускам някоя проверка, но ще се радвам ако някой ми помогне.

Кодът ми е следния :

Благодаря предварително ! :)

Animal Sanctuary

You work in an animal sanctuary and every day you receive encrypted information about the animals that need help.

Create a program that decrypts messages about animals, their kind and the country they are in. You will be given a number n – the number of lines, which you will receive. Afterwards on the next n lines, you will receive the messages. You are looking for:

  • animalName
    • contains any ASCII character except for ";”
  • animalKind
    • contains any ASCII character except for “;”
  • animalCountry
    • contains only letters and spaces

A valid message is in the following format: "n:{animalName};t:{animalKind};c--{animalCountry}"

The output names, kinds and countries of the animals should contain only letters and white spaces. For example:
"K@o$5a#la Be^4a5r" is a valid match, but we need to print only – "Koala Bear". After each valid message, you should print a line in the format:

"{animalName} is a {animalKind} from {country}"

You need to know the total weight of all the animals. The weight of each animal alone is calculated by the sum of every digit in the name and the kind of the animal. In the end print a line in the following format with the following message:

"Total weight of all animals is {weight}KG".

Input / Constraints

  • First line will be a number n in range [1…100].
  • The next n lines will be strings.


  • Print each valid message in the format described above.
  • Print the total weight of all animals.








Marley is a Bear from Australia

George is a Cat from Africa

Total weight of animals: 34KG


The first two lines are valid matches and the third is not, because it is not in the right format. We take the digits in the names and kinds of the two valid matches - M5%ar4#le@y, B3#e!!a2#2r, G3e%6or34ge, C€$at2% - 5 + 4 + 3 + 2 + 2 + 3 + 6 + 3 + 4 + 2 = 34. After each of the valid lines, we print the appropriate message. In the end we print the total weight of all animals, which is 34.







Bobbie is a Elephant from Africa

Honey is a Tiger from India

Total weight of animals: 42KG


Fundamentals Module
Petar088 avatar Petar088 3 Точки

И аз съм на 90 %?

msmner avatar msmner 37 Точки


Изпускаш случая, в който името на страната съдържа други символи освен букви и празни полета. Ето го кодът ти с вариант за проверка за валидност на страната:

Вариант с РегЕкс:


manevpsp avatar manevpsp 8 Точки

Аз също съм на 90, но ми гърми различен от твоя тест 

Теста кой то ти гърми според е свързан с това

  • contains only letters and spaces

трябва да имаш САМО букви и SPACE


Ето ти примерен вход :       n:G3e%6org34e;t:C€$at2%;c--North Macedonia 

ппс моя код:

22/11/2019 22:59:06