fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int matrix[2][101], ord[101], n, count = 1;
  6.  
  7. void sort() {
  8. int finished = 0, size = n, swapped;
  9. while(!finished) {
  10. swapped = 0;
  11. for(int i = 1; i < size; ++i) {
  12. if(matrix[1][ord[i]] > matrix[1][ord[i+1]]) {
  13. int temp = ord[i];
  14. ord[i] = ord[i+1];
  15. ord[i+1] = temp;
  16. swapped = 1;
  17. }
  18. }
  19. if(swapped) size--;
  20. else finished = 1;
  21. }
  22. }
  23.  
  24. int main(int argc, char const *argv[]) {
  25. int hour1, min1, hour2, min2;
  26. cout<<"Number of Spectacles = ";
  27. cin>>n;
  28. for(int i = 1; i <= n; ++i) {
  29. ord[i] = i;
  30. cin>>hour1>>min1>>hour2>>min2;
  31. matrix[ 0 ][ i ] = hour1 * 60 + min1;
  32. matrix[ 1 ][ i ] = hour2 * 60 + min2;
  33. }
  34.  
  35. for(int i = 1; i <= n; ++i) {
  36.  
  37. cout<<ord[i]<<" "<<matrix[0][i]<<" "<<matrix[1][i]<<"\n";
  38. }
  39.  
  40. for(int i = 1; i <= n; ++i) {
  41.  
  42. cout<<ord[i]<<" ";
  43. }
  44.  
  45. sort();
  46.  
  47. cout<<endl;
  48.  
  49. for(int i = 1; i <= n; ++i) {
  50.  
  51. cout<<ord[i]<<" ";
  52. }
  53.  
  54. cout<<endl;
  55.  
  56. int curr = matrix[1][ord[1]];
  57.  
  58. cout<<ord[1]<<" ";
  59.  
  60. for(int i = 2; i <= n; ++i) {
  61.  
  62. if(matrix[0][ord[i]] >= curr) {
  63.  
  64. cout<<ord[ i ]<<" ";
  65.  
  66. curr = matrix[ 1 ][ ord[ i ] ];
  67.  
  68. count++;
  69. }
  70. }
  71.  
  72. cout<<"Count = "<<count;
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 5504KB
stdin
10
5 00 14 00
14 00 17 00
8 00 13 00
13 00 15 00
15 00 17 00
3 00 6 00
4 00 7 00
6 00 9 00
11 00 14 00
10 00 11 00
stdout
Number of Spectacles = 1 300 840
2 840 1020
3 480 780
4 780 900
5 900 1020
6 180 360
7 240 420
8 360 540
9 660 840
10 600 660
1 2 3 4 5 6 7 8 9 10 
6 7 8 10 3 1 9 4 2 5 
6 8 10 9 2 Count = 5