선배님들 에러발생부분좀 알려주세요 ㅠㅠ
첫번째 입력 : 0000011111 (문자열)
두번째 입력 : 0,5
0번째 문자에서 5번째 문자들중에 0,1 둘다 있으면 NO 이고 1만있거나 0만있으면 YES
segmentation fault 에러 발생부분좀 알려주세요 ㅠㅠ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include <stdio.h> #include <stdlib.h> #include <string.h> void f_zeroone(char *point,int s,int e); int result[1000]; int n =0; int main() { char zeroone[10000]; int cnt=0,cnt_s=0; int s=0,e=0; scanf("%s",zeroone); scanf("%d",&cnt); cnt_s = cnt; while(cnt>0) { scanf("%d %d",&s,&e); f_zeroone(zeroone,s,e); cnt--; } for(cnt = 0;cnt<cnt_s;cnt++) { if(result[cnt]) printf("YES\n"); else printf("NO\n"); } return 0; } void f_zeroone(char *point,int s,int e) { int i=0; int zerochk=0,onechk=0; if(s>e) { int temp = e; e = s; s = temp; } for(i=s;i<=e;i++) { if((int)point[i]==48){ zerochk++; } else onechk++; } if(zerochk<1 && onechk > 0) //11111 { result[n] = 1; n++; } else if(zerochk > 0 && onechk >0 ) //0011 { result[n] = 0; n++; } else { result[n] = 1; //000000 n++; } } |
댓글 0