fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, m, k, cnt = 0, f = 0, st = 0;
  6. char s[50], e[50], tmp[50];
  7. scanf("%d %d %d", &n, &m, &k);
  8. while(k--){
  9. scanf("%s %d", &tmp, &f);
  10.  
  11. if(f == 1){
  12. if(m + 1 < n) m++;
  13. else{
  14. st = 1;
  15. m = n;
  16. }
  17. }
  18. else if(f == 0){
  19. m--;
  20. }
  21. if(m < n){
  22. if(st && cnt - 1 > 0){
  23. printf("%s %d \n", tmp, cnt - 1);
  24. cnt = 0;
  25. }
  26. st = 0;
  27. }
  28.  
  29. //printf("%d ", st);
  30.  
  31. if(st){
  32. if(!cnt){
  33. printf("%s-", tmp);
  34. }
  35. cnt++;
  36. }
  37. }
  38. if(st) printf("%s %d \n", tmp, cnt - 1);
  39. }
  40.  
  41. /*
  42. INPUT
  43. 10 8 6
  44. 08:15 1
  45. 08:25 1
  46. 08:45 1
  47. 08:50 1
  48. 09:10 0
  49. 09:15 0
  50.  
  51. OUTPUT
  52. 08:45-09:10 2
  53.  
  54. */
Success #stdin #stdout 0s 5312KB
stdin
10 9 6 
08:15 1
08:25 0
08:45 1
08:50 0
09:10 1
09:15 0
stdout
08:15-08:50 1 
09:10-