fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector <int> arr={3,6,2,3,5};
  6. int n=arr.size();
  7. int x=0,y=0,turn=0,reverse=0,i=0,j=n-1;
  8. while(i<=j){
  9. if(reverse==0){
  10. if(arr[i]%2==0){
  11. reverse=1;
  12. }
  13. if(turn%2==0){
  14. x+=arr[i];
  15.  
  16. }else{
  17. y+=arr[i];
  18. }
  19. i++;
  20. }else{
  21. if(arr[j]%2==0){
  22. reverse=0;
  23. }
  24. if(turn%2==0){
  25. x+=arr[j];
  26. }else{
  27. y+=arr[j];
  28. }
  29.  
  30. j--;
  31. }
  32. cout<<turn<<" "<<x<<" "<<y<<" "<<reverse<<endl;
  33. turn++;
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40. cout<<x<<endl;
  41. cout<<y;
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
0  3  0   0
1  3  6   1
2  8  6   1
3  8  9   1
4  10  9   0
10
9