Advertisement
rfop

Untitled

Apr 28th, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8.  {
  9.         int tamanhoarray,casos;
  10.         scanf("%d", &casos);
  11.         while(casos !=0){
  12.             int contde1=0,aux=0;
  13.             scanf("%d", &tamanhoarray);
  14.             int array[tamanhoarray],numeros;
  15.             for(int cont=0; cont<tamanhoarray; cont++){
  16.                 scanf("%d", &numeros);
  17.                 if(numeros == 1){
  18.                     contde1++;
  19.                     array[cont] = numeros;
  20.                 } else {
  21.                     array[cont] = numeros;
  22.                     aux++;
  23.                 }
  24.                 }
  25.                 size_t size = sizeof(array) / sizeof(array[0]);
  26.                 sort(array, array + size);
  27.                 for(int cont=0; cont<=contde1; cont++){
  28.                     printf("1 ";)
  29.                 }
  30.                 for(int cont=0; cont<=tamanhoarray-1; cont++){
  31.                     if(array[cont] == 3 && array[cont+1]== 2 && array[cont] != tamanhoarray-1){
  32.                         array[cont] = 2;
  33.                         array[cont+1] = 3;
  34.                     }
  35.                 }
  36.  
  37.                 for(int cont=aux; cont>=tamanhoarray-1; cont++){
  38.                     printf("%d ",array[cont]);
  39.  
  40.                     }
  41.  
  42.             cout<<endl;
  43.             casos--;
  44.         }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement