ENG  RUSTimus Online Judge
Online Judge
О системе
Часто задаваемые вопросы
Новости сайта
Архив задач
Отправить на проверку
Состояние проверки
Исправить данные
Рейтинг авторов
Текущее соревнование
Прошедшие соревнования

1274. Fractional Arithmetic

Ограничение времени: 1.0 секунды
Ограничение памяти: 64 МБ
Your task is to write a program, which implements addition, subtraction, multiplication and division operations on fractions. Input and output fraction format is as follows:
  • the sign of a number (must be written only if its absence may lead to misrepresentation of the number),
  • the integer part of a number (the integer part that equals zero must be omitted if the numerator and the denominator are present),
  • a space character (must be omitted if the integer or fractional part is absent),
  • the numerator (if it is not equal to zero),
  • the “/” sign (written only if there is a numerator),
  • the denominator (must be omitted if there is no numerator),
  • the denominator cannot be equal to zero.
Samples of fractional number representation: “-7 3/4”, “8 1/2”, “-7/11”, “0”, “11”.
All limitations apply for both input and output data. The sign of a fraction: if the fraction is positive, the sign is not written; if the fraction is negative, the “-” sign must be present. The integer part and the numerator may have values ranging from 0 to 30000, the denominator may have values from 1 to 30000. The operation sign may be one of the four possible symbols: “+” (addition), “-” (subtraction), “*” (multiplication), “/” (division). The expression is always correct, so the second operand in the division operation cannot be zero.

Исходные данные

The first line – a fraction (the first operand);
The second line – the sign of an operation;
The third line – a fraction (the second operand).
Both fractions may be reducible. The numerator is always less than the denominator.


A single line that contains an irreducible proper fraction (result) in the format described above.


исходные данныерезультат
-3 1/6
-2 2/3
Автор задачи: © Sergey G. Volchenkov, 2003(volchenkov@yandex.ru); Vladimir N. Pinaev, 2003(vpinaev@mail.ru; http://www.pic200x.chat.ru); Michael Y. Kopachev, 2003 (mkopachev@krista.ru).
Источник задачи: 2003-2004 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 15-16, 2003