Advertisement
Tkap1

Untitled

Apr 27th, 2024
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. for(int command_index = 0; command_index < command_count; command_index++)
  2. {
  3.     char* command = g_commands[command_index];
  4.     int command_len = (int)strlen(command);
  5.     assert(command_len > 0);
  6.  
  7.     int score = 0;
  8.     int start = 0;
  9.     int highest_streak = 0;
  10.     int streak = 0;
  11.     for(int input_char_index = 0; input_char_index < input_len; input_char_index++)
  12.     {
  13.         char input_c = console->input_str.text[input_char_index];
  14.         for(int command_char_index = start; command_char_index < command_len; command_char_index++)
  15.         {
  16.             char command_c = command[command_char_index];
  17.             if(command_c == input_c)
  18.             {
  19.                 start = command_char_index + 1;
  20.                 streak += 1;
  21.                 highest_streak = max(streak, highest_streak);
  22.                 score += 1;
  23.                 break;
  24.             }
  25.             else
  26.             {
  27.                 streak = 0;
  28.             }
  29.         }
  30.     }
  31.     score += highest_streak;
  32.     s_auto_complete_command acc = zero;
  33.     acc.score = score;
  34.     acc.index = command_index;
  35.     accs[command_index] = acc;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement