Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream in("input.txt");
  6. ofstream out("output.txt");
  7.  
  8. int main()
  9. {
  10. int N,Q,postris,app,a=0,cont=0,element=0;
  11. in>>N;
  12. in>>Q;
  13. int treno[N];
  14. for(int i=0; i<N; i++)
  15. treno[i]=-1;
  16. char evento;
  17. for(int i=0;i<Q;i++)
  18. {
  19. in>>evento;
  20. in>>postris;
  21. if(evento=='b')
  22. {
  23. for(int j=0;j<N;j++)
  24. {
  25. if(treno[j]==-1)
  26. {
  27. treno[j]=postris;
  28. j=N;
  29. }
  30. else if(j==postris)
  31. {
  32. app=treno[j];
  33. treno[j]=postris;
  34. postris=app;
  35. cont++;
  36. a=0;
  37. do
  38. {
  39. if(treno[postris]!=-1)
  40. {
  41. app=treno[postris];
  42. treno[postris]=postris;
  43. postris=app;
  44. cont++;
  45. }
  46. else
  47. {
  48. treno[postris]=postris;
  49. a=-1;
  50. }
  51. }while(a>=0);
  52. j=N;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. for(int k=0;k<N;k++)
  59. {
  60. if(treno[k] == postris)
  61. {
  62. treno[k]=-1;
  63. k=N;
  64. }
  65. }
  66. }
  67. }
  68. out<<cont;
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement