Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int main(void)
- {
- char bubble1[10]={0};
- char bubble2[10]={0}; //燈泡狀態,
- int ch_Sec[10]={0};//變燈秒數
- int i,length=0,sec=0;
- gets(bubble1);
- gets(bubble2);
- length =strlen(bubble1);
- for (i=0;i<length;i++)
- {
- ch_Sec[i]=pow(2,i);
- sec = sec+(int)(bubble2[i]-'0')*ch_Sec[i];
- //bubble2[i][0]以字元的形式存在,所以剪掉字元0
- }
- int next_sec=sec+1; //這裡ok
- for (i=0;i<length;i++)
- {
- if(next_sec%ch_Sec[i]==0) //此行造成了無窮迴圈
- //下一秒可被所需秒數除盡的燈泡才會變燈
- {
- /* 不對, 因為印到第2維了
- if (bubble2[i][0]==0){bubble2[i][0]=1;}
- if (bubble2[i][0]==1){bubble2[i][0]=0;}
- */
- if (bubble2[i]=='0'){
- bubble2[i]='1';
- printf ("%c",bubble2[i]);
- }
- if (bubble2[i]=='1'){
- bubble2[i]='0';
- printf ("%c",bubble2[i]);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement