fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector <int> v;
  6. while(true) {
  7. char c;
  8. cin >> c ;
  9. if (c==']') break;
  10. int a;
  11. cin >> a;
  12. v.push_back(a);
  13. }
  14. list <int> l;
  15. for (auto a : v){
  16. l.push_back(a);
  17. }
  18. int s = l.size();
  19. if(s%2==0) {
  20. int p=((s/2));
  21. cout << "[" << *next(l.begin(),p) ;
  22. for (int i=p+1 ; i<s ; i++) {
  23. cout << "," << *next(l.begin(),i) ;
  24. }
  25. cout << "]";
  26. }
  27. else {
  28. int p=((s/2));
  29. cout << "[" << *next(l.begin(),p) ;
  30. for (int i=p+1 ; i<s ; i++) {
  31. cout << "," << *next(l.begin(),i) ;
  32. }
  33. cout << "]";
  34. }
  35.  
  36. return 0;
  37.  
  38. }
Success #stdin #stdout 0.01s 5312KB
stdin
[1,2,3,4,5]
stdout
[3,4,5]