fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct
  4. {
  5. int l, r;
  6. }soldier;
  7.  
  8. int main()
  9. {
  10. soldier sold[101000];
  11. int i, s, b, r, l;
  12. while(scanf("%d %d", &s, &b) && s)
  13. {
  14. for(i=1;i<=s;i++)
  15. {
  16. sold[i].l = i-1;
  17. sold[i].r = i+1;
  18. }
  19. sold[s].r = 0;
  20. for(i=0;i<b;i++)
  21. {
  22. scanf("%d%d", &l, &r);
  23. sold[sold[l].l].r = sold[r].r;
  24. sold[sold[r].r].l = sold[l].l;
  25. if(sold[l].l == 0 && sold[r].r == 0) printf("* *\n");
  26. else if(sold[l].l == 0) printf("* %d\n", sold[r].r);
  27. else if(sold[r].r == 0) printf("%d *\n", sold[l].l);
  28. else printf("%d %d\n", sold[l].l, sold[r].r);
  29. }
  30. printf("-\n");
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 4012KB
stdin
1 1
1 1
10 4
2 5
6 9
1 1
10 10
5 1
1 1
0 0
stdout
* *
-
1 6
1 10
* 10
* *
-
* 2
-