Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int total,min,max,nilai,count,kasus;
- FILE *fp=fopen("random.txt","r");
- fscanf(fp,"%d\n",&kasus);
- for(int x=0;x<kasus;x++)
- {
- fscanf(fp,"%d %d %d\n",&total,&min,&max);
- char string[total];
- count=0;
- nilai=1;
- fscanf(fp,"%s\n",string);
- for(int j=0;j<strlen(string);j++)
- {
- if(string[j]=='1'&&string[j+1]=='1')
- {
- nilai++;
- if(nilai>max)
- {
- nilai=1;
- }
- else if(nilai>=min && nilai<=max)
- {
- if(string[j+1]=='1'&&string[j+2]=='0')
- {
- count++;
- nilai=1;
- }
- else if(string[j+1]=='1'&&string[j+2]=='\0')
- {
- count++;
- nilai=1;
- }
- }
- }
- else if(string[j]=='1'&&string[j+1]=='0')
- {
- if(nilai>max)
- {
- nilai=1;
- }
- else if(nilai>=min && nilai<=max)
- {
- if(string[j+1]=='0' && string[j-1]=='\0')
- {
- count++;
- nilai=1;
- }
- else if(string[j+1]=='0' && string[j-1]=='0')
- {
- count++;
- nilai=1;
- }
- }
- }
- else if(string[j]=='1' && string[j+1]=='\0')
- {
- if(nilai>max)
- {
- nilai=1;
- }
- else if(nilai>=min && nilai<=max)
- {
- count++;
- nilai=1;
- }
- }
- else
- nilai=1;
- }
- printf("Case #%d: %d\n",x+1,count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement