main2.c (990B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 typedef struct Cord_ Cord; 5 6 typedef struct Cord_ { 7 int x,y; 8 Cord *next, *prev; 9 } Cord; 10 11 Cord* updateTail(Cord *head, Cord *tail) 12 { 13 int dy, dx, d; 14 dx = head->x - tail->x; 15 dy = head->y - tail->y; 16 d = dx * dx + dy * dy; 17 // distance <= 1 18 if ( d <= 2) return tail; 19 tail->x += (dx + dx/abs(dx))/2; 20 tail->y += (dy + dy/abs(dy))/2; 21 22 return tail; 23 } 24 25 int main() 26 { 27 char c; 28 int d; 29 Cord h[10] = {0}; 30 while (scanf("%c %d\n", &c, &d) != EOF) 31 { 32 printf("%c %d\n", c, d); 33 for (int i = 0; i < d; i++) 34 { 35 h[0].x += (c == 'R') - (c == 'L'); 36 h[0].y += (c == 'U') - (c == 'D'); 37 printf("H %d %d \n", h->x, h->y); 38 for (int i = 0; i < 9; i++) 39 { 40 updateTail(&h[i], &h[i+1]); 41 } 42 printf("T %d %d \n", h[9].x, h[9].y); 43 } 44 } 45 46 } 47 48 // ./main < input2.txt | grep T | sort | uniq | wc -l 49 50