fork download
  1. #include <stdio.h>
  2.  
  3. struct Record
  4. {
  5. size_t start;
  6. size_t end;
  7. size_t freq;
  8. };
  9. void display(const struct Record *records, const struct Record *record_x, const struct Record *record_y, size_t length);
  10. size_t count_digits(size_t n);
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. struct Record record_x, record_y;
  15. size_t length;
  16. scanf("%u %u %u %u\n", &record_x.start, &record_x.end, &record_y.start, &record_y.end);
  17. scanf("%u", &length);
  18. struct Record records[length];
  19. for(size_t i = 0; i < length; i++)
  20. scanf("%u %u %u\n", &records[i].start, &records[i].end, &records[i].freq);
  21. display(records, &record_x, &record_y, length);
  22.  
  23. return 0;
  24. }
  25.  
  26. void display(const struct Record *records, const struct Record *record_x, const struct Record *record_y, size_t length)
  27. {
  28. size_t left_pad = count_digits(record_y->end);
  29. for(size_t freq = record_y->end; freq >= record_y->start; freq--)
  30. {
  31. printf("%*u", left_pad, freq);
  32. for(size_t i = 0; i < length; i++)
  33. {
  34. printf("%*c", count_digits(records[i].start), ' ');
  35. printf("%c", records[i].freq >= freq ? '*' : ' ');
  36. }
  37. printf("\n");
  38. }
  39. printf("%*c", left_pad, ' ');
  40. for(size_t i = 0; i < length; i++)
  41. printf("%u ", records[i].start);
  42. printf("%u\n", records[length - 1].end);
  43. }
  44.  
  45. size_t count_digits(size_t n)
  46. {
  47. if(n == 0)
  48. return 1;
  49. for(size_t i = 1, count = 0; ; i *= 10, count++)
  50. if(n / i == 0)
  51. return count;
  52. }
Success #stdin #stdout 0s 2172KB
stdin
0 50 1 10
	5
	0 10 1
	10 20 3
	20 30 6
	30 40 4
	40 50 2
stdout
10              
 9              
 8              
 7              
 6       *      
 5       *      
 4       *  *   
 3    *  *  *   
 2    *  *  *  *
 1 *  *  *  *  *
  0 10 20 30 40 50