Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int entrada;
- cin >> entrada; //1
- int c = 1;
- int array[50];
- array[0] = entrada;
- int cont = 1;
- while(entrada != 0 && c != 0){
- cin >> c;
- if(c != 0){
- array[cont] = c;
- }
- cont++;
- }
- //novo array
- int array2[cont-1];
- for(int i = 0; i < cont-1; i++){
- array2[i] = array[i];
- }
- //for(int j = 0; j < cont-1; j++){
- // cout << array2[j] << endl;
- //}
- int tamanhoArray = cont-1;
- //Vamos agora descartar e pegar o último
- //primeiro elemento é o topo
- int arrayRetiradas[tamanhoArray];
- int total = tamanhoArray;
- int p = 1;
- for(int i = 0; i < tamanhoArray; i++){ //posso fazer com while
- if(total > 1){
- arrayRetiradas[i] = array2[i];
- //array2[i] = 0;
- total = total - 1;
- //permuta
- int inicio = i + p; //proximo que sera o inicio
- int final = array2[tamanhoArray]; //armazena o último
- array2[tamanhoArray] = array2[inicio];
- array2[inicio] = final;
- p = p + 1;
- }
- }
- for(int j = 0; j < 2; j++){
- cout << arrayRetiradas[j] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement