https://vjudge.net/contest/167883#problem/F
我tm郁闷,比赛中发现不合格的情况只有cfc 和cc这俩货,然后我就直接find了,一直wa。我就在考虑我去肯定有没考虑到的,想的样例都能过。是在是想不到为啥啊。。
后来队友把他的代码处理了非c非f的情况就a了。
然后今天我才发现我的也是。。。。好坑。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{ int m;
string a;
string g="cc";
string gg="cfc";
cin>>m;
for(int i=1;i<=m;i++){
cin>>a;
int len=a.length();
a+=a;
bool flag=false;
if(a.find(g)!=a.npos)
{ //puts("@");
flag=true;}
if(a.find(gg)!=a.npos)
flag=true;
int sum=0;
bool w=false;
for(int i=0;i<a.length();i++)
{if(a[i]=='c')
sum++;
if(a[i]!='c'&&a[i]!='f')
flag=true;
}
if(sum==0){
if(flag)
printf("Case #%d: -1\n",i);
else
printf("Case #%d: %d\n",i,len/2+len%2);
}
else
{ if(flag)
printf("Case #%d: -1\n",i);
else
printf("Case #%d: %d\n",i,sum/2);
}
}
return 0;
}
队友的,因为他没有加所以 处理了最后的一个和第一个的情况。其他都差不多。就是判断的情况不一样。现在想想也就只有这俩情况对吧哈哈。。
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
char c[1000050];
int a[1000050];
int main()
{
int t;
scanf("%d",&t);
for(int cas=1;cas<=t;cas++)
{
int j=0,f=0;
scanf("%s",c);
int len=strlen(c);
memset(a,0,sizeof(a));
for(int i=0;i<len;i++)
{
if(c[i]=='c')
a[j++]=i;
if(c[i]!='c'&&c[i]!='f')
{
f=1;break;
}
}
for(int i=1;i<=j-1;i++)
{
if(a[i]-a[i-1]<3){f=1;break;}
}
if(j==0)
{
if(f==1)
{printf("Case #%d: -1\n",cas);continue;}
if(len%2==0)
printf("Case #%d: %d\n",cas,len/2);
else
printf("Case #%d: %d\n",cas,len/2+1);
}
else
{
if(f==1)
{printf("Case #%d: -1\n",cas);continue;}
else if(len-a[j-1]-1+a[0]<2)
{printf("Case #%d: -1\n",cas);continue;}
else printf("Case #%d: %d\n",cas,j);
}
}
return 0;
}