Предмет: Информатика, автор: bananas22

Сдать решение задачи 5-Летоисчисление
Полный балл: 10
Ограничение времени: 500 мс
Ограничение памяти: 512M
Ограничение размера стека: 64M
Задача 5: Летоисчисление
В григорианском календаре года нумерются числами 1, 2, 3 и т.д., это года “нашей эры”. Предшествующие года называются “первый год до нашей эры”, “второй год до нашей эры” и т.д.

Будем обозначать года нашей эры положительными числами, а года до нашей эры — отрицательными. При этом года с номером 0 не существует, то есть нумерация лет выглядит так: ..., −3, −2, −1, 1, 2, 3, ...

В летописях написано, что какое-то событие произошло в году номер A, а другое событие произошло спустя n лет после первого события (или за n лет до первого события). Определите, в каком году произошло второе событие.

Входные данные
Первая строка входных данных содержит число A — год, в котором произошло первое событие. Вторая строка содержит число n. Если n > 0, то второе событие произошло через n лет после первого события, а если n < 0, то второе событие произошло за |n| лет до первого события. Оба числа могут быть как положительными, так и отрицательными.

Выходные данные
Программа должна вывести одно целое число — номер года, в который произошло второе событие.

Система оценивания
Решение, правильно работающее только для случаев, когда все входные числа по модулю не превосходят 100, будет оцениваться в 6 баллов.

В 10 баллов будет оцениваться решение, правильно работающее, когда все входные числа по модулю не превосходят 109.

Примеры
Ввод Вывод Пояснение
5
-3
2
Первое событие произошло в 5 году, второе событие произошло за 3 года до первого, это был 2 год.

-3
1
-2
Первое событие произошло в 3 году до н.э., второе событие произошло через 1 год, это 2 год до н.э.. Ответ: -2.

-3
4
2
Первое событие произошло в 3 году до н.э., второе событие произошло через 4 года. Отсчитываем 4 года: 2 год до н.э., 1 год до н.э., 1 год н.э., 2 год н.э. Ответ: 2.

Сдать решение
Язык:
Файл
Отправить!

Ответы

Автор ответа: Baffys
6

Ответ:

y1 = int(input())

r = int(input())

if abs(y1) <= abs(r) and ((y1 > 0 and r < 0) or (y1 < 0 and r > 0)):

if r > 0:

y2 = y1 + r + 1

elif r < 0:

y2 = y1 + r — 1

else:

y2 = y1 + r

print(y2)

Объяснение:

Решение, правильно работающее только для случаев, когда все входные числа по модулю не превосходят 100, будет оцениваться в 60 баллов. В 100 баллов будет оцениваться решение, правильно работающее, когда все входные числа по модулю не превосходят 109.


woki223: а какой язык
YrrahRottep: вроде паскаль
Похожие вопросы
Предмет: Английский язык, автор: Аноним
Прочитайте текст. Заполните пропуски 1-7 частями
предложений, обозначенные буквами A - H. Одна из частей лишняя.


 

The Golden Duck

  
A.
Не always helped poor people because he knew the meaning of happiness.


   B. In the evening, though, he still had lots of
money left.


  
C. One day he complained about his poverty to an old man.


 
  D. The princess
made a magic spell and gave him a hundred gold coins.


   
E.
He bought a lot of expensive things and
spent all the money.


  F. There he
searched the dungeons.


 G. Hard work and good health bring happiness, not
money.


   
H. The shoemaker felt sorry for him and gave him some money.


              

Once upon a time there was an unhappy
shoemaker. He wanted to be rich because he thought
this was the only way to be happy. (1) The old man told him what to do.
"Go to the castle and look for the golden duck. It's really a
princess, and she will tell you what to do."


The shoemaker
was excited and went to the castle. (2) When he saw the duck, she turned into a
beautiful princess. "I want to be rich
and happy," he said. (3) "Spend all this money tomorrow," the
princess said, "but only on yourself, not on other people. Then when you have nothing I will make you
rich." "This is easy,"
thought the shoemaker, and the next day he started spending the money. (4) Then
he met an old soldier, a beggar, with
one leg. "I'm hungry, help me," he said. (5) The magic spell stopped working, and the princess appeared.
"You gave some money to another person," she said. "I cannot
make you rich." Then the old soldier said to the shoemaker, "Don't be
unhappy. (6)" At last the
shoemaker understood. He .worked hard, saved money and started his own shop. In time he got married and had a family.
(7) And he lived happily ever after.


 

 
Предмет: Русский язык, автор: лошадкаком
Предмет: Английский язык, автор: Аноним
помогите плиз ребят   Ticket 17

Прочитайте текст. Заполните пропуски 1-8 частями
предложений, обозначенные буквами A - I. Одна из частей лишняя.


 

A. After the last animal walked onto the ark, it
started to rain.


B.  They caught
fish and enjoyed their voyage.


C.  He was kind to all people.

D.  They were safe with the animals on the ark.

E.   One day the bird returned with an olive branch in
his mouth.

E   Noah started to build the ark.


G. But Noah could not help them.

H. Most people on the earth are not as
kind as you.

I.  
The sun appeared.


Noah's Ark

Noah was a very good man. He was not wealthy, but he was
honest and he worked hard. (1) He
believed in God and he prayed every day. He lived with his wife and
his children. One day, God spoke to Noah. He said, "Noah, I know that you
are a good man. (2) I am going to create a large storm.
I will destroy all of the bad things on the earth, but I will save
you and your family." Then God said,
"Build a large ark, Noah. Take your family on the ark with you. Also, take
two of every animal on the earth. Bring food and supplies for several months." (3) All of the people in the city
said that he was crazy, but Noah ignored them.
He believed what God said to him. Noah finished his ark. He
gathered his family and he gathered two of all of the animals on
the earth. (4) It rained and rained and rained. All of the people in
the city were frightened. They said, "Noah, help us! Let us
on your boat!" (5) It rained for forty days
and forty nights. It was the greatest flood ever. All of the people on the earth died in the flood. Noah and his
family floated on the water. (6) The rain stopped after forty days. (7)
"Noah wanted to see where land was. He
picked a bird from the ark. He said
to the bird, "I see only water around us. Fly away, bird! See if land is anywhere nearby!" But the bird
returned with no sign of land. Noah
continued this every day. (8) Noah saw the olive branch and understood that land was near. He said to his
wife, "Land is here! We are safe! God
saved us!"
Предмет: Алгебра, автор: Nikname69