fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve(){
  5. int n;
  6. cin >> n;
  7.  
  8. // Read input values into a vector (if needed)
  9. vector<int> a(n);
  10. for (int i = 0; i < n; i++){
  11. cin >> a[i];
  12. }
  13.  
  14. // Create empty vectors for odds and evens
  15. vector<int> b;
  16. vector<int> c;
  17.  
  18. // Separate the numbers into odd and even vectors
  19. for (int i = 0; i < n; i++){
  20. if (a[i] % 2 == 1) {
  21. b.push_back(a[i]);
  22. } else {
  23. c.push_back(a[i]);
  24. }
  25. }
  26.  
  27. // If either vector is empty, output -1
  28. if(b.empty() || c.empty()){
  29. cout << -1 << endl;
  30. return;
  31. }
  32.  
  33. // Print odd numbers
  34. for (int x : b) {
  35. cout << x << " ";
  36. }
  37. cout << endl;
  38.  
  39. // Print even numbers
  40. for (int x : c) {
  41. cout << x << " ";
  42. }
  43. cout << endl;
  44.  
  45. // for(int x = 0; x < n; x++){
  46. // if(a[x] == -1){
  47. // i++;
  48. // }else if(a[x] == 1){
  49. // j++;
  50. // }
  51. // }
  52.  
  53. // while(i>j){
  54. // i--;
  55. // j++;
  56. // count++;
  57. // }
  58.  
  59.  
  60.  
  61. }
  62.  
  63. int main() {
  64. int t;
  65. cin>>t;
  66. while(t--){
  67. solve();
  68. }
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
3
2 2 2
5
1 2 3 4 5
3
1 3 5
7
1 7 7 2 9 1 4
5
4 8 12 12 4
stdout
-1
1 3 5 
2 4 
-1
1 7 7 9 1 
2 4 
-1