QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#4850. 数学

统计

小伊戈尔(Igor)在暑假期间完全没有练习数学,因此在开学前几天,他意识到自己已经记不清基本的数学运算了。现在他缠着哥哥达沃(Davor)帮他练习。

为了让练习变得有趣,达沃让伊戈尔想一个整数。接着,达沃多次要求伊戈尔对他想出的数字进行加、减、乘或除以另一个整数的操作。在进行除法运算时,伊戈尔总是使用整数除法(例如,$-27$ 除以 $10$ 的结果是 $-2$)。练习结束时,伊戈尔大声说出最终结果,而达沃的任务是猜出伊戈尔最初想的数字。

请编写一个程序,根据给定的操作序列和最终结果,确定伊戈尔最初可能想出的不同整数有多少个。

输入格式

第一行包含一个自然数 $N$ ($1 \le N \le 10$),表示操作次数。

接下来的 $N$ 行中,每行包含一种操作,格式为以下四种之一:“DODAJ x”、“ODUZMI x”、“POMNOZI SA x”、“PODIJELI SA x”,其中 $x$ 是一个整数,$1 \le x \le 9$。

最后一行包含最终结果,即一个整数 $R$ ($-100 \le R \le 100$)。

输出格式

输出一行,包含伊戈尔最初可能想出的不同整数的个数。

样例

输入 1

1
POMNOZI SA 5
8

输出 1

0

说明 1

不存在任何整数,将其乘以 $5$ 后得到 $8$。

输入 2

2
POMNOZI SA 3
PODIJELI SA 2
-1

输出 2

1

说明 2

伊戈尔唯一可能想到的数字是 $-1$。

输入 3

4
DODAJ 5
PODIJELI SA 5
ODUZMI 5
PODIJELI SA 5
1

输出 3

25

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.