#include #include char clockwork[100]; int len; int getFunction_K(int K){ int counter = 0; for(int i = 0; i <= (len-1)-K; i++){ if(clockwork[i] == '1'){ if(clockwork[i+K] == '0')counter++; } } return counter; } int main(){ scanf("%s",clockwork); len = strlen(clockwork); if(clockwork[0] == '0'){ // opti printf("-1\n"); return 0; } int itercount = 0; while(1){ //printf("%s jelenlegi\n",clockwork); int currmax; int max = 0; int maxk = 0; for(int i = 1; i <= len-1; i++){ currmax = getFunction_K(i); if(currmax > max){ max = currmax; maxk = i; } } //printf("MaxK = %d\n",maxk); char copy[len+1]; int countofone = 0; for(int i = 0; i < len+1;i++){ copy[i] = clockwork[i]; } for(int i = 0; i < len; i++){ if(copy[i] == '1'){ clockwork[i+maxk] = '1'; } if(clockwork[i] == '1')countofone++; } itercount++; //printf("countofone: %d\n",countofone); if(countofone == len){ printf("%d\n",itercount); break; } } hell:; return 0; }