杭电4639

 

居然在最后的输出形式那里卡了很久,忘记除10007,忘记输出Case 希望下次不要犯这种错误

#include "iostream"
#include "string.h"
using namespace std;
int f[10100][100],maxb=0;
char list[110][10100];
int max(int a,int b){return a>b?a:b;}

void work(){
  int i,count,flag,j,num;
  memset(f,0,sizeof(f));
  f[0][0]=1;
  f[1][0]=1;
  f[2][0]=2;
  f[3][0]=3;
  count=1;
  for(i=4;i<=maxb;i++){
    flag=0;
    for(j=0;j<count;j++){
     f[i][j]=f[i-1][j]+f[i-2][j]+flag;
     flag=f[i][j]/10;
     f[i][j]=f[i][j]%10;
    }
    if(flag!=0){
      f[i][j]=flag;
      count++;
    }
    flag=0;
    if(f[i][4]>=1){
      flag=1;
      if(f[i][3]>=0){
        flag=1;
        if(f[i][2]>=0){
          flag=1;
          if(f[i][1]>=0){
            flag=1;
            if(f[i][0]>=7){
              flag=1;
            }
          }
        }
      }
    }
    if(flag){
      num=f[i][4]*10000+f[i][3]*1000+f[i][2]*100+f[i][1]*10+f[i][0];
      num=num%10007;
      f[i][4]=num/10000;
      num=num%10000;
      f[i][3]=num/1000;
      num=num%1000;
      f[i][2]=num/100;
      num=num%100;
      f[i][1]=num/10;
      f[i][0]=num%10;
    }
    count=4;
    //cout<<"* ";cout<<i<<' ';for(j=count-1;j>=0;j--)cout<<f[i][j];cout<<endl;
  }
}

int chang(int a){
    return f[a][4]*10000+f[a][3]*1000+f[a][2]*100+f[a][1]*10+f[a][0];
}

void work1(int a){
  int data=0,number=1,i;
  for(i=0;i<strlen(list[a]);i++){
    if(list[a][i]=='h'&&list[a][i+1]=='e'){data++;i++;}
    else {
     // cout<<data<<" ++++ "<<i<<endl;
      number*=chang(data);
      if(number>10007)
      number=number%10007;
      data=0;
    }
  }
  //cout<<data<<"()"<<endl;
  if(data!=0)number*=chang(data);
  if(number>10007)number=number%10007;
  cout<<"Case "<<a<<": "<<number<<endl;
}

int main(){
   int Case,i=1;
   cin>>Case;
   while(Case--){
      cin>>list[i];
      maxb=strlen(list[i]);
      work();
      work1(i);
      i++;
   }
}

 

 

posted @ 2013-08-18 00:26  龙城星  阅读(176)  评论(0编辑  收藏  举报