Animal Sanctuary
Loading...
Vesolini avatar Vesolini 5 Точки

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

Здравейте,

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

Кодът ми е следния : https://pastebin.com/sKa8xUGk

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

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.

Output

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

Examples

Input

Output

3

n:M5%ar4#le@y;t:B3#e!!a2#2r;c--Australia

n:G3e%6org34e;t:C€$at2%;c--Africa

n:AlicE:Won;c-India

Marley is a Bear from Australia

George is a Cat from Africa

Total weight of animals: 34KG

Comments

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.

 

4

n:Bo^%4b35454bie#$;t:Ele5ph#$34a%nt;c--Africa

n:Honey;t:Ti^^5ger;c--India

bla;t:1234a;c--America

n:A#$@545n;t:Cat241$@#23;cGermany

Bobbie is a Elephant from Africa

Honey is a Tiger from India

Total weight of animals: 42KG

 

Тагове:
0
Fundamentals Module
Petar088 avatar Petar088 3 Точки

И аз съм на 90 %?

0