Skip to content

Instantly share code, notes, and snippets.

@Rockbet
Last active May 8, 2019 01:23
Show Gist options
  • Save Rockbet/685c2f14f104d2c27cc5881d7088e102 to your computer and use it in GitHub Desktop.
Save Rockbet/685c2f14f104d2c27cc5881d7088e102 to your computer and use it in GitHub Desktop.
// Noic - Iniciante - Semana 55 - Problema 2
// O(N)
#include <bits/stdc++.h>
using namespace std;
int main(){
//um representa a quantidade de 1's, e dois a quantidade de 2's
int n, um=0, dois=0;
cin >> n;
for(int i=1; i<=n; i++){
int x;
cin >> x;
if(x==1)um++;
else dois++;
}
if(dois==0){
for(int i=1; i<=n; i++){
cout << 1 << " ";
}
return 0;
}
else if(um==0){
for(int i=1; i<=n; i++){
cout << 2 << " ";
}
return 0;
}
for(int i=1; i<=n; i++){
if(i==1){
cout << 2 << " ";
dois--;
}
if(i==2){
cout << 1 << " ";
um--;
}
if(i>=3){
if(dois>=1){
cout << 2 << " ";
dois--;
}
else{
if(um>=1){
cout << 1 << " ";
um--;
}
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment