CF464C.Substitutes in Number

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "d__i → t__i", that means "replace all digits d__i in string s with substrings equal to t__i". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.

Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!

安德鲁和叶甫根尼正在玩一个游戏。初始时,安德鲁拥有一个由数字组成的字符串 ss。叶甫根尼向安德鲁发送多个形如 “di→tid_i \to t_i” 的查询,其含义为:“将字符串 ss 中所有数字 did_i 替换为子串 tit_i”。例如,若 s=123123s = 123123,则查询 “2→002 \to 00” 将 ss 变为 1003100310031003;而查询 “$3 \to $”(即“将 33 替换为空字符串”)将 ss 变为 12121212。在执行完所有查询后,叶甫根尼要求安德鲁求出:将最终字符串 ss 视作十进制数时,该数对 10000000071000000007(即 109+710^9 + 7)取模所得的余数。注意:将 ss 解释为十进制数时,应忽略前导零;若 ss 为空字符串,则视其表示的数为 00。

安德鲁已厌倦手动处理叶甫根尼的请求,于是请你编写一个程序来完成这项任务。请帮助他!

输入格式

The first line contains string s (1 ≤ |s| ≤ 105), consisting of digits — the string before processing all the requests.

The second line contains a single integer n (0 ≤ n ≤ 105) — the number of queries.

The next n lines contain the descriptions of the queries. The i-th query is described by string "d__i->t__i", where d__i is exactly one digit (from 0 to 9), t__i is a string consisting of digits (t__i can be an empty string). The sum of lengths of t__i for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed.

第一行包含一个字符串 ss(1≤∣s∣≤1051 \leq |s| \leq 10^5),由数字组成——即所有操作前的原始字符串。

第二行包含一个整数 nn(0≤n≤1050 \leq n \leq 10^5)——查询的数量。

接下来的 nn 行描述了这些查询。第 ii 个查询由字符串 "di→tid_i\rightarrow t_i" 描述,其中 did_i 是恰好一位数字(从 0 到 9),tit_i 是一个由数字组成的字符串(tit_i 可以为空字符串)。所有查询中 tit_i 的长度之和不超过 10510^5。查询按需执行的顺序给出。

输出格式

Print a single integer — remainder of division of the resulting number by 1000000007 (109 + 7).

输出一个整数——结果数对 1000000007(109+710^9 + 7)取模的余数。

输入输出样例

  • 输入#1

    123123
    1
    2->00

    输出#1

    10031003
  • 输入#2

    123123
    1
    3->

    输出#2

    1212
  • 输入#3

    222
    2
    2->0
    0->7

    输出#3

    777
  • 输入#4

    1000000008
    0

    输出#4

    1

说明/提示

Note that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample).

注意,替换后字符串 s 中的前导零不会被删除(可在第三个样例中看到)。

输入解题思路,AI测评打分。不知道怎么写?

首页