fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. vector<int>lina;
  8.  
  9. int z, n, ruch, x;
  10.  
  11. int main()
  12. {
  13. cin>>z;
  14. while(z--)
  15. {
  16. lina.clear();
  17. cin>>n;
  18. for(int i=0; i<n; ++i)
  19. {
  20. cin>>x;
  21. lina.push_back(x);
  22. }
  23. ruch=1;
  24. if(n==1)
  25. {
  26. cout<<"1"<<endl;
  27. continue;
  28. }
  29. for(int i=0; i<n-2; ++i)
  30. {
  31. if(lina[i]==1)
  32. {
  33. if(ruch==1)
  34. ruch=2;
  35. else
  36. ruch=1;
  37. continue;
  38. }
  39. if(lina[i+1]==1)
  40. {
  41. if(ruch==1)
  42. ruch=2;
  43. else
  44. ruch=1;
  45. continue;
  46. }
  47.  
  48. }
  49. if(lina[n-2]==1)
  50. {
  51. if(ruch==1)
  52. {
  53. cout<<"2"<<endl;
  54. }
  55. else
  56. cout<<"1"<<endl;
  57. }
  58. else
  59. cout<<ruch<<endl;
  60.  
  61. }
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty