HDU 5455 Fang Fang(模拟)

思路:直接模拟就好了,注意全是f的情况


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 1000000 + 100;
char s[maxn];
int pos[maxn];

int main()
{
	int T, cas=1, n;
	scanf("%d", &T);
	while(T--)
	{
		int f=1, cn=0;
		scanf("%s", s);
		n = strlen(s);
		for(int i=0;s[i];++i)
		{
			if(s[i]=='c') pos[cn++]=i;
			if(s[i]!='c'&&s[i]!='f'){
				f=0; break;
			}
		}
		printf("Case #%d: ", cas++);

		if(!f) puts("-1");
		else
		{
			if(cn==0)
			{
				printf("%d\n", n/2+n%2);
				continue;
			}

			for(int i=0;i<cn-1;++i)
			{
				if(pos[i+1]-pos[i]<3)
				{
					f=0; break;
				}
			}
			if(n-pos[cn-1] + pos[0] < 3) f=0;
			if(!f) puts("-1");
			else printf("%d\n", cn);
		}

	}
	
	return 0;
}


Description

Fang Fang says she wants to be remembered. 
I promise her. We define the sequence   of strings. 
 
 
 
 
Write down a serenade as a lowercase string   in a circle, in a loop that never ends. 
Spell the serenade using the minimum number of strings in  , or nothing could be done but put her away in cold wilderness.

Input

An positive integer  , indicating there are   test cases. 
Following are   lines, each line contains an string   as introduced above. 
The total length of strings for all test cases would not be larger than  .

Output

The output contains exactly   lines. 
For each test case, if one can not spell the serenade by using the strings in  , output  . Otherwise, output the minimum number of strings in   to split   according to aforementioned rules. Repetitive strings should be counted repeatedly.

Sample Input

8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc

Sample Output

Case #1: 3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值