Advertisement
Five_NT

[C++]Prob. spectacolelor

Nov 4th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("progr.in");
  7.  
  8. struct spec
  9. {
  10.     int ti, ts, td, nr;
  11. } a[100];
  12.  
  13. int i, j, n;
  14.  
  15. void citire()
  16. {
  17.     f>>n;
  18.     for(i=1; i<=n; i++)
  19.     {
  20.         f>>a[i].ti;
  21.         f>>a[i].ts;
  22.         a[i].td=a[i].ts-a[i].ti;
  23.     }
  24. }
  25.  
  26. void ordonare()
  27. {
  28.     spec aux;
  29.     for(i=1; i<=n; i++)
  30.         for(j=1; j<=n; j++)
  31.             if(a[i].ts<a[j].ts)
  32.             {
  33.                 aux=a[i];
  34.                 a[i]=a[j];
  35.                 a[j]=aux;
  36.             }
  37. }
  38.  
  39. void afis()
  40. {
  41.     cout<<"Spectacolul "<<1<<" dureaza "<<a[1].td<<"ore. [ "<<a[1].ti<<" - "<<a[1].ts<<" ]"<<endl;
  42.     for(i=2; i<=n; i++)
  43.         if(a[i].ti >= a[i-1].ts)
  44.         {
  45.             cout<<"Spectacolul "<<i<<" dureaza "<<a[i].td<<"ore. [ "<<a[i].ti<<" - "<<a[i].ts<<" ]"<<endl;
  46.         }
  47.    
  48. }
  49. int main()
  50. {
  51.     citire();
  52.     ordonare();
  53.     afis();
  54.     return 0;
  55. }
  56. /* Exemplu:
  57. "progr.in"
  58. 6       //nr spectacole
  59. 18 20   //spec nr 1
  60. 10 12   //spec nr 2
  61. 15 18   //spec nr 3
  62. 20 23   //spec nr 4
  63. 15 16   //spec nr 5
  64. 16 17   //spec nr 6
  65.  
  66. Se v-a afisa:
  67. Spectacolul 2 [ 10 - 12 ]
  68. Spectacolul 5 [ 15 - 16 ]
  69. Spectacolul 6 [ 16 - 17 ]
  70. Spectacolul 1 [ 18 - 20 ]
  71. Spectacolul 4 [ 20 - 23 ]
  72. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement