CiscoOA #15
Create New Version
估计简单评测数据准备中,可先阅读题面
考点(AI 标注)字符串
Given a string s mixing letters and single digits, build an output string by scanning s left to right:
- Letters accumulate into a buffer
buf. - A digit
dflushes the buffer: appendbufto the outputdtimes (sod == 1keeps it once;d == 0discards it). - Whatever letters remain in
bufat the end are appended as-is.
Return the resulting string.
Constraints
1 ≤ len(s) ≤ 10⁴scontains lowercase letters and digits0-9.
Example 1
Input:
s = "cisco"
Output:
"cisco"
Explanation: The given string is "cisco" and contains all letters so add it to the output string (using rule number 1). So, the output will be "cisco".
Example 2
Input:
s = "cisco2india"
Output:
"ciscociscoindia"
Explanation: The given string is "cisco2india" which contains one digit '2' after "cisco" so by using rule number 2, we get "ciscocisco" and the remaining substring "india" it is added to the output string using rule number 1. So, the output is "ciscociscoindia".