Advertisement
ramomjcs

Quest1

Mar 12th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int entrada;
  6. cin >> entrada; //1
  7. int c = 1;
  8.  
  9. int array[50];
  10. array[0] = entrada;
  11.  
  12. int cont = 1;
  13. while(entrada != 0 && c != 0){
  14. cin >> c;
  15. if(c != 0){
  16. array[cont] = c;
  17. }
  18. cont++;
  19. }
  20. //novo array
  21. int array2[cont-1];
  22.  
  23. for(int i = 0; i < cont-1; i++){
  24. array2[i] = array[i];
  25. }
  26.  
  27. //for(int j = 0; j < cont-1; j++){
  28. // cout << array2[j] << endl;
  29. //}
  30.  
  31.  
  32.  
  33.  
  34. int tamanhoArray = cont-1;
  35.  
  36. //Vamos agora descartar e pegar o último
  37. //primeiro elemento é o topo
  38.  
  39. int arrayRetiradas[tamanhoArray];
  40.  
  41. int total = tamanhoArray;
  42.  
  43. int p = 1;
  44.  
  45. for(int i = 0; i < tamanhoArray; i++){ //posso fazer com while
  46.  
  47. if(total > 1){
  48. arrayRetiradas[i] = array2[i];
  49. //array2[i] = 0;
  50. total = total - 1;
  51. //permuta
  52. int inicio = i + p; //proximo que sera o inicio
  53. int final = array2[tamanhoArray]; //armazena o último
  54. array2[tamanhoArray] = array2[inicio];
  55. array2[inicio] = final;
  56.  
  57. p = p + 1;
  58.  
  59. }
  60.  
  61. }
  62.  
  63. for(int j = 0; j < 2; j++){
  64. cout << arrayRetiradas[j] << endl;
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement