Advertisement
SuitNdtie

CodeCube BruteForce

May 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. char codecube[10] = {"codecube"};
  5. char str[100010];
  6. int len;
  7.  
  8. int cost(int I,int J){
  9.     int c = 0;
  10.     int ci = 0;
  11.     for(int i = I ; i <= J && ci < 8 ; i ++){
  12.         if(str[i] == codecube[ci]){
  13.             ci++;
  14.         }else{
  15.             c++;
  16.         }
  17.     }
  18.     return (ci == 8 ? c : 1e9);
  19. }
  20.  
  21.  
  22.  
  23. int main(){
  24.     scanf("%s",str);
  25.     len = strlen(str);
  26.    
  27.     int anscost = 1e9;
  28.     int ansI,ansJ;
  29.     for(int i = 0 ; i < len - 7 ; i ++ ){
  30.         for(int j = i + 7 ; j < len ; j ++){
  31.             int tcost = cost(i,j);
  32.             if(tcost < anscost){
  33.                 anscost = tcost;
  34.                 ansI = i;
  35.                 ansJ = j;
  36.             }
  37.         }
  38.     }
  39.     if(anscost == 1e9){
  40.         printf("-1");
  41.         return 0;
  42.     }
  43.     printf("%d %d",ansI+1,ansJ+1);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement