Gemstones(牛客第八场多校)
鏈接:https://ac.nowcoder.com/acm/contest/888/G
來源:牛客網(wǎng)
Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.
After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the gemstone sequence each time, after taking away three gemstones, the left two parts of origin sequence will be merged to one sequence in origin order automatically.
For example, as for “ATCCCTTG”, we can take three 'C’s away with two parts “AT”, “TTG” left, then the two parts will be merged to “ATTTG”, and we can take three 'T’s next time.
The password of this level is the maximum possible times to take gemstones from origin sequence.
Please help them to determine the maximum times.
輸入描述:
Only one line containing a string s_{}s
?
, denoting the gemstone sequence, where the same letters are regarded as the same types.
1 \le |s| \le 10^51≤∣s∣≤10
5
s_{}s
?
only contains uppercase letters.
輸出描述:
Print a non-negative integer in a single line, denoting the maximum times.
示例1
輸入
復(fù)制
ATCCCTTG
輸出
復(fù)制
2
說明
One possible way is that ATCCCTTG\," \; \rightarrow \;ATTTG," ; \rightarrow ``AG,"‘‘ATCCCTTG"→‘‘ATTTG"→‘‘AG"
挺迷惑人的一個題。因為這個數(shù)量是確定的,所以直接遍歷一邊就行。假如我們找到了三個相同的字母,我們就直接把他刪除掉。再往前回兩個位置,因為最多就是前兩個和后面一個會組成三個相同的字母。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Gemstones(牛客第八场多校)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019牛客第八场A All-one
- 下一篇: CDMA(牛客第八场构造题)