hdu5455(2015沈阳网络赛F题)
生活随笔
收集整理的這篇文章主要介紹了
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题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu5459(2015沈阳网络赛J题)
- 下一篇: hdu5452(2015沈阳网络赛C题)