有一把 n 个锁轮的锁,每个锁轮上写有数字 ai ,对于第 i 个锁轮,做了 bi 次操作。这些操作有两种类型:
U:锁轮上的数字 +1 ,超过 9 则变为 0 。D:锁轮上的数字 −1 ,小于 0 则变为 9 。现在给定操作后的锁轮和操作,请你还原操作前的锁轮。
第一行一个整数 t ,表示测试点内数据组数。
每组数据中第一行是一个正整数 n ,表示锁轮数。
下一行有 n 个整数 ai ,表示每个锁轮操作后的数字。
以下 ai-> n 行,第 i 行包含整数 bi 和 bi 个字符 U 或 D ,含义见题目描述。
一行 n 个用空格隔开的整数,表示操作前锁轮上的数字。
1≤n,t≤100,0≤ai≤9,1≤bi≤10
Luca has a cypher made up of a sequence of n wheels, each with a digit ai written on it. On the i -th wheel, he made bi moves. Each move is one of two types:
Example for n=4 . The current sequence is 0 0 0 0.Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
The first line contains a single integer t ( 1≤t≤100 ) — the number of test cases.
The first line of each test case contains a single integer n ( 1≤n≤100 ) — the number of wheels.
The second line contains n integers ai ( 0≤ai≤9 ) — the digit shown on the i -th wheel after all moves have been performed.
Then n lines follow, the i -th of which contains the integer bi ( 1≤bi≤10 ) and bi characters that are either U or D — the number of moves performed on the i -th wheel, and the moves performed. U and D represent an up move and a down move respectively.
For each test case, output n space-separated digits — the initial sequence of the cypher.
3
3
9 3 1
3 DDD
4 UDUU
2 DU
2
0 9
9 DDDDDDDDD
9 UUUUUUUUU
5
0 5 9 8 3
10 UUUUUUUUUU
3 UUD
8 UUDUUDDD
10 UUDUUDUDDU
4 UUUU
2 1 1
9 0
0 4 9 6 9
In the first test case, we can prove that initial sequence was [2,1,1] . In that case, the following moves were performed:
The final sequence was [9,3,1] , which matches the input.
源码:
# Cypher
## 题面翻译
## 题目描述
有一把 $n$ 个锁轮的锁,每个锁轮上写有数字 $a_i$ ,对于第 $i$ 个锁轮,做了 $b_i$ 次操作。这些操作有两种类型:
- `U`:锁轮上的数字 $+1$ ,超过 $9$ 则变为 $0$ 。
- `D`:锁轮上的数字 $-1$ ,小于 $0$ 则变为 $9$ 。
现在给定操作后的锁轮和操作,请你还原操作前的锁轮。
## 输入格式
第一行一个整数 $t$ ,表示测试点内数据组数。
每组数据中第一行是一个正整数 $n$ ,表示锁轮数。
下一行有 $n$ 个整数 $a_i$ ,表示每个锁轮操作后的数字。
以下 $n$ 行,第 $i$ 行包含整数 $b_i$ 和 $b_i$ 个字符 `U` 或 `D` ,含义见题目描述。
## 输出格式
一行 $n$ 个用空格隔开的整数,表示操作前锁轮上的数字。
## 数据范围
$1 \le n,t \le 100,0 \le a_i \le 9,1 \le b_i \le 10$
## 题目描述
Luca has a cypher made up of a sequence of $ n $ wheels, each with a digit $ a_i $ written on it. On the $ i $ -th wheel, he made $ b_i $ moves. Each move is one of two types:
- up move (denoted by $ \texttt{U} $ ): it increases the $ i $ -th digit by $ 1 $ . After applying the up move on $ 9 $ , it becomes $ 0 $ .
- down move (denoted by $ \texttt{D} $ ): it decreases the $ i $ -th digit by $ 1 $ . After applying the down move on $ 0 $ , it becomes $ 9 $ .
Example for $ n=4 $ . The current sequence is 0 0 0 0.Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
## 输入格式
The first line contains a single integer $ t $ ( $ 1 \leq t \leq 100 $ ) — the number of test cases.
The first line of each test case contains a single integer $ n $ ( $ 1 \leq n \leq 100 $ ) — the number of wheels.
The second line contains $ n $ integers $ a_i $ ( $ 0 \leq a_i \leq 9 $ ) — the digit shown on the $ i $ -th wheel after all moves have been performed.
Then $ n $ lines follow, the $ i $ -th of which contains the integer $ b_i $ ( $ 1 \leq b_i \leq 10 $ ) and $ b_i $ characters that are either $ \texttt{U} $ or $ \texttt{D} $ — the number of moves performed on the $ i $ -th wheel, and the moves performed. $ \texttt{U} $ and $ \texttt{D} $ represent an up move and a down move respectively.
## 输出格式
For each test case, output $ n $ space-separated digits — the initial sequence of the cypher.
## 样例 #1
### 样例输入 #1
3 3 9 3 1 3 DDD 4 UDUU 2 DU 2 0 9 9 DDDDDDDDD 9 UUUUUUUUU 5 0 5 9 8 3 10 UUUUUUUUUU 3 UUD 8 UUDUUDDD 10 UUDUUDUDDU 4 UUUU
### 样例输出 #1
2 1 1 9 0 0 4 9 6 9
## 提示
In the first test case, we can prove that initial sequence was $ [2,1,1] $ . In that case, the following moves were performed:
- On the first wheel: $ 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{D}]{} 9 $ .
- On the second wheel: $ 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{D}]{} 1 \xrightarrow[\texttt{U}]{} 2 \xrightarrow[\texttt{U}]{} 3 $ .
- On the third wheel: $ 1 \xrightarrow[\texttt{D}]{} 0 \xrightarrow[\texttt{U}]{} 1 $ .
The final sequence was $ [9,3,1] $ , which matches the input.