日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【CF#801 A.】 Vicious Keyboard(字符串查找,水题)

發(fā)布時(shí)間:2023/12/10 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CF#801 A.】 Vicious Keyboard(字符串查找,水题) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

Tonio has a keyboard with only two letters, "V" and "K".

One day, he has typed out a string?s?with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i.?e. a letter "K" right after a letter "V") in the resulting string.

Input

The first line will contain a string?s?consisting only of uppercase English letters "V" and "K" with length not less than?1?and not greater than?100.

Output

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

Examples InputVK Output1 InputVV Output1 InputV Output0 InputVKKKKKKKKKVVVVVVVVVK Output3 InputKVKV Output1

題目大意:給你一個(gè)字符串,改其中一個(gè)字母或者不改,然后讓你從中找有幾個(gè)VK。

解題報(bào)告:?? ? 思維題啊,找?guī)捉M數(shù)據(jù)測(cè)試一下就找出規(guī)律來(lái)了,就是先去掉VK的(記錄下來(lái)ans個(gè)),然后看有沒(méi)有VV或者KK,有的話(huà)就輸出ans+1,沒(méi)有的話(huà)就輸出ans


ac代碼:

#include<iostream> #include<cstdio> #include<cstring>using namespace std;const int N = 100 + 5; char a[N]; bool bk[N]; int ans = 0, flag = 0; int main() {cin>>a;int len = strlen(a);for(int i = 0; i < len; i++) {if(a[i] == 'V' && a[i + 1] == 'K') {ans++;bk[i]=1;bk[i+1]=1;}}for(int i = 0; i < len; i++) {if(bk[i]==0&&bk[i+1]==0&&a[i]==a[i + 1]) flag=1;}if(flag==1) ans++;printf("%d\n", ans);return 0 ; }



總結(jié)

以上是生活随笔為你收集整理的【CF#801 A.】 Vicious Keyboard(字符串查找,水题)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。