Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<vector>
- using namespace std;
- int main(){
- int t; scanf("%d", &t);
- while(t--){
- int n; scanf("%d", &n);
- vector<int> positive;
- vector<int> negative;
- for(int i = 0; i < n; i++){
- int k; scanf("%d", &k);
- if(k < 0){
- negative.push_back(k);
- }
- else positive.push_back(k);
- }
- int count = 0;
- auto a = positive.begin();
- auto b = negative.begin();
- while((a != positive.end()) && (b != negative.end())){
- count++;
- if(count % 2){
- printf("%d ", *a++);
- //positive.erase(positive.begin());
- }
- else {
- printf("%d ", *b++);
- // negative.erase(negative.begin());
- }
- }
- if(a == positive.end()){
- while(b != negative.end()){
- printf("%d ", *b++);
- //negative.erase(negative.begin());
- }
- }
- else{
- while(a != positive.end()){
- printf("%d ", *a++);
- //positive.erase(positive.begin());
- }
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement