Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- typedef struct _circle{
- int num;
- struct _circle *prev;
- } Circle;
- //環状リストを用いたタイマー
- //要は2->1->0->9がスムーズにできる
- int main(int argc, char *argv[]){
- int cnt=0, i;
- if(argc != 2){
- printf("Error: Usage: ./timer n(second)\n");
- return 0;
- }
- cnt = atoi(argv[1]);
- Circle one[10], two[6], three[10], *p1, *p2, *p3;
- for(i=0; i<10; i++){
- if(i<6){
- two[i].num = i;
- two[i].prev = &two[(i+5)%6];
- }
- one[i].num = three[i].num = i;
- one[i].prev = &one[(i+9)%10];
- three[i].prev = &three[(i+9)%10];
- }
- //タイマーセット
- p1 = &one[cnt/60];
- p2 = &two[(cnt%60)/10];
- p3 = &three[(cnt%60)%10];
- while(cnt>0){
- printf("残り %d:%d%d\n", p1->num, p2->num, p3->num);
- sleep(1);
- if(p3->prev->num == 9){
- p2 = p2->prev;
- if(p2->num == 5){
- p1 = p1->prev;
- }
- }
- p3 = p3->prev;
- cnt--;
- printf("\033[1A");
- }
- printf("Time Up\a\n");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement