QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#8110. 加法 / Sumowanie

Statistiques

你的任务很简单——将两个数字相加!遗憾的是,这太简单了,所以我们得增加一点难度。

PAScript 是一种全新的脚本语言。该语言的脚本包含 $k$ 行:第 $i$ 行包含两个非空单词 $a_i, b_i$,由可打印的 ASCII 字符(编号从 33 到 126)组成。PAScript 的解释器从输入中读取字符串 $s$,并执行以下伪代码:

while true:
    foundReplacement = false
    for i = 1, 2, ..., k:
        if a(i) is a substring of s:
            replace the leftmost occurrence of a(i) with b(i)
            foundReplacement = true
            break
    if not foundReplacement:
        break
print(s)

你的任务是找到一个有效的脚本,用于将两个二进制数字相加。脚本的输入将是一个形如 binary number + binary number 的字符串,不含空格和前导零。一个正确的输入示例如 10001+1001。这两个二进制数字表示非负整数。输入字符串的长度不超过 100。

你的脚本也应输出输入数字之和的二进制表示,同样不含前导零。对于上述示例,结果应为 11010

你的脚本还应简短且有效。具体来说,它必须满足以下条件:

  • $k \le 50$(脚本行数不超过 50 行);
  • $1 \le |a_i|, |b_i| \le 8$(脚本中的单词长度不超过 8 个字符且不能为空);
  • 对于每个输入,解释器执行外部 while 循环的次数不超过 100,000 次。此外,在脚本的整个执行过程中,字符串 $s$ 的长度永远不会超过 2017 个字符。

输入格式

本题没有输入。

输出格式

输出的第一行应包含一个整数 $k$ ($1 \le k \le 50$),表示脚本的行数。接下来的 $k$ 行中,第 $i$ 行应表示脚本的第 $i$ 行,因此应包含两个由单个空格分隔的非空单词 $a_i, b_i$。

样例

样例 1

6
00 0
01 1
10 1
11 1
0 NO
1 YES

说明

警告:当然,上述示例脚本并不能解决上述任务。另一方面,该示例脚本对于仅包含 0 和 1 的字符串,可以判断其中是否至少包含一个 1。

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.