Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. typedef struct _circle{
  6. int num;
  7. struct _circle *prev;
  8. } Circle;
  9.  
  10. //環状リストを用いたタイマー
  11. //要は2->1->0->9がスムーズにできる
  12. int main(int argc, char *argv[]){
  13. int cnt=0, i;
  14. if(argc != 2){
  15. printf("Error: Usage: ./timer n(second)\n");
  16. return 0;
  17. }
  18. cnt = atoi(argv[1]);
  19.  
  20. Circle one[10], two[6], three[10], *p1, *p2, *p3;
  21. for(i=0; i<10; i++){
  22. if(i<6){
  23. two[i].num = i;
  24. two[i].prev = &two[(i+5)%6];
  25. }
  26. one[i].num = three[i].num = i;
  27. one[i].prev = &one[(i+9)%10];
  28. three[i].prev = &three[(i+9)%10];
  29. }
  30.  
  31. //タイマーセット
  32. p1 = &one[cnt/60];
  33. p2 = &two[(cnt%60)/10];
  34. p3 = &three[(cnt%60)%10];
  35. while(cnt>0){
  36. printf("残り %d:%d%d\n", p1->num, p2->num, p3->num);
  37. sleep(1);
  38. if(p3->prev->num == 9){
  39. p2 = p2->prev;
  40. if(p2->num == 5){
  41. p1 = p1->prev;
  42. }
  43. }
  44. p3 = p3->prev;
  45. cnt--;
  46. printf("\033[1A");
  47. }
  48. printf("Time Up\a\n");
  49. return 1;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement