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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu5455(2015沈阳网络赛F题)

發布時間:2025/3/15 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu5455(2015沈阳网络赛F题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

給出一個串,問用題中定義的那些串來組成這個串最少要用多少個。


思路:

沒啥說的,注意一下輸入的串中可能出現除了c和f的字母。


代碼:

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<map> #include<vector> #include<string> #include<set> #include<queue> #include<stack> #include<cmath> #include<climits>using namespace std;char ch[1000100];int main() {int t;int kase = 1;scanf("%d", &t);while (t--) {scanf("%s", ch);int start = -1;int len = strlen(ch);int ook = 0;for (int i = 0; i < len; i++) {if ( ! (ch[i] == 'c' || ch[i] == 'f')) {ook = 1;printf("Case #%d: -1\n", kase++);break;}}if (ook == 1) {continue;}for (int i = 0; i < len; i++) {if (ch[i] == 'c') {start = i;break;}}if (start == -1) {int nans = 0;nans = len / 2;if (len & 1) {nans++;}printf("Case #%d: %d\n", kase++, nans);}else {int ans = 0;int ok = 0;int numf = -1;for (int i = start; i < len; i++) {if (ch[i] == 'c') {if (numf == -1 || numf >= 2) {ans++;numf = 0;}else {ok = 1;break;}}else {numf++;}if (ok == 1) {break;}}if (ok != 1) {for (int i = 0; i < start; i++) {if (ch[i] == 'c') {if (numf == -1 || numf >= 2) {ans++;numf = 0;}else {ok = 1;break;}}else {numf++;}if (ok == 1) {break;}}}if ( !(numf == -1 || numf >= 2)) {ok = 1;}if (ok == 1) {printf("Case #%d: -1\n", kase++);}else {printf("Case #%d: %d\n", kase++, ans);}}}return 0; }

總結

以上是生活随笔為你收集整理的hdu5455(2015沈阳网络赛F题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。