#include <stdio.h> #include <stdlib.h> #define SIZE 10000 int test_main(int data[SIZE]); int test_main(int data[SIZE]) { int count=0; for(int i=0;i<SIZE-7;i++){ if(data[i]=='O'&&data[i+1]=='O'&&data[i+2]=='X'){ i=i+3; while(data[i]=='X')i++; if(data[i]=='O'&&data[i+1]=='O'&&data[i+2]=='X'){ i=i+3; while(data[i]=='X')i++; count++; } } } return count; } /* int test_main(int data[SIZE]){ int num=0; for(int i=0;i<SIZE;i++){ if(data[i]=='O'&&data[i+1]=='O'&&data[i+2]=='X') { int x=0; while((i+3+x)<SIZE&&data[i+3+x]=='X') { x++; } x=x+3; if(data[i+x]=='O'&&data[i+x+1]=='O'&&data[i+x+2]=='X'){ int y=0; while((i+3+y)<SIZE&&data[i+3+y]=='X') { y++; } y=y+3; if((i+y)<SIZE&&data[i+y]=='O') { num++; } } } } return num; } */ static int data[SIZE]; static void build_data(void) { for (int a = 0; a < SIZE; a++) { data[a] = (rand() % 2) ? 'O' : 'X'; } } void main(void) { for (int l = 0; l < 10; l++) { build_data(); printf("%d ", test_main(data)); } } #include <stdio.h> #include <stdlib.h> #define SIZE 10000 int test_main(int data[SIZE]); static int data[SIZE]; int temp=0; int Count=0; static void build_data(void) { for (int a = 0; a < SIZE; a++) { data[a] = (rand() % 2) ? 'O' : 'X'; } } void main(void) { for (int l = 0; l < 10; l++) { build_data(); printf("%d ", test_main(data)); Count=0; }while(1); } int test_main(int data[10000]) { for(temp=0;temp<9993;) { if((data[temp]=='O')&&(data[temp+1]=='O')&&(data[temp+2]=='X')) { temp+=3; while(data[temp]=='X') temp++; if(data[temp+1]=='O') { if(data[temp+2]=='X')////////////////// { temp+=3; while(data[temp]!='O') temp++; Count++; temp++; } else { temp-=1;/////////////////// continue; }///////////////////////////// } else { temp++; continue; } } else temp++; } return Count; }