Advertisement
eddiehy

Untitled

Sep 26th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. int main(void)
  6. {
  7. char bubble1[10]={0};
  8. char bubble2[10]={0}; //燈泡狀態,
  9. int ch_Sec[10]={0};//變燈秒數
  10. int i,length=0,sec=0;
  11. gets(bubble1);
  12. gets(bubble2);
  13. length =strlen(bubble1);
  14. for (i=0;i<length;i++)
  15. {
  16. ch_Sec[i]=pow(2,i);
  17. sec = sec+(int)(bubble2[i]-'0')*ch_Sec[i];
  18. //bubble2[i][0]以字元的形式存在,所以剪掉字元0
  19. }
  20. int next_sec=sec+1; //這裡ok
  21. for (i=0;i<length;i++)
  22. {
  23. if(next_sec%ch_Sec[i]==0) //此行造成了無窮迴圈
  24. //下一秒可被所需秒數除盡的燈泡才會變燈
  25. {
  26. /* 不對, 因為印到第2維了
  27. if (bubble2[i][0]==0){bubble2[i][0]=1;}
  28. if (bubble2[i][0]==1){bubble2[i][0]=0;}
  29. */
  30. if (bubble2[i]=='0'){
  31. bubble2[i]='1';
  32. printf ("%c",bubble2[i]);
  33. }
  34. if (bubble2[i]=='1'){
  35. bubble2[i]='0';
  36. printf ("%c",bubble2[i]);
  37. }
  38. }
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement