Problem Statement
Iroha has a sequence of positive integers
A
=
(
A
1
,
A
2
,
…
,
A
N
)
A = (A_1, A_2, \dots, A_N)
A=(A1,A2,…,AN) of length
N
N
N (
N
≥
1
N \ge 1
N≥1).
She generated a string
S
S
S using
A
A
A as follows:
- Start with
S
=
S =
S=
|
. - For
i
=
1
,
2
,
…
,
N
i = 1, 2, \dots, N
i=1,2,…,N, perform the following operations in order:
- Append
A
i
A_i
Ai copies of
-
to the end of S S S. - Then, append one
|
to the end of S S S.
- Append
A
i
A_i
Ai copies of
Given the generated string S S S, reconstruct the sequence A A A.
中文题意
问题陈述
Iroha有一个长度为
N
N
N (
N
≥
1
N \ge 1
N≥1 )的正整数序列
A
=
(
A
1
,
A
2
,
…
,
A
N
)
A = (A_1, A_2, \dots, A_N)
A=(A1,A2,…,AN) 。
她使用
A
A
A 生成了一个字符串
S
S
S ,如下所示:
- 以 S = S = S= ‘ | ’开头。
- 对于 i = 1 , 2 , … , N i = 1, 2, \dots, N i=1,2,…,N ,依次执行如下操作:
- 在 S S S 的末尾追加 A i A_i Ai 个“-”副本。
- 然后,在 S S S 后面添加一个‘ | ’。
给定生成的字符串 S S S ,重建序列 A A A 。
Constraints
- S S S is a string of length between 3 3 3 and 100 100 100, inclusive, generated by the method in the problem statement.
- A A A is a sequence of positive integers of length at least 1 1 1.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer in the following format, with elements separated by spaces in a single line:
A 1 A_1 A1 A 2 A_2 A2 … \dots … A N A_N AN
Sample Input 1
|---|-|----|-|-----|
Sample Output 1
3 1 4 1 5
$S = $ |---|-|----|-|-----|
is generated by
A
=
(
3
,
1
,
4
,
1
,
5
)
A = (3, 1, 4, 1, 5)
A=(3,1,4,1,5).
Sample Input 2
|----------|
Sample Output 2
10
Sample Input 3
|-|-|-|------|
Sample Output 3
1 1 1 6
解法
这里使用一个技巧,避开第一个 |
,直接从第二个字符开始计数,意味着把每一个---|
看成一对。使用一个变量 cnt
统计 -
的个数,如果遇到|
输出cnt
,同时令cnt = 0
即可。
string s;
void solved() {
/* your code */
cin >> s;
int cnt = 0;
for (int i = 1; i < s.size(); i ++) {
if(s[i] == '|') {
cout << cnt << " ";
cnt = 0;
}
}
}