COMO FAZER UM PROGRAMA

Eu preciso de uma ajuda para poder fazer 2 programas.
1- Com conjunto com n(n<=20) números e informar se existe algum elemento repetido no conjunto.

2- Com Conjunto com n(n<=30) números qualquer e imprima-os sem repetições.
entrada: 1,1,3,4,3,5,-8
saída: 1,3,4,5,-8

POR FAVOR PESSOAL, SE ME PUDEREM AJUDAR
VALE PONTOS NA FACULDADE.
I don't follow Portugese very well, but I'll do my best.

1 - For n<=20 elements, use a brute-force n2 method: check that element 1 != any element in 3..n; then check that element 2 != any element in 4..n; etc. That'll take two loops, one inside the other.

2 - You'll need a second array. Copy the numbers from the first array to the second array, but only copy a number if it is not already in the second array. (You can check because if it is, it'll be the last number copied.)

(Technically, you don't need a second array. You only need to remember what the last number you copied/printed was.)

Hope this helps.
> You only need to remember what the last number you copied/printed was
For (2) it does not says that the input is sorted. You can solve it with a simple variation of the solution for (1) where you would not check all the range, but only the already visited values.

Edit: or when (1) reports a repeated element, you simply continue the loop

> por favor pessoal, se me puderem ajudar
> vale pontos na faculdade.
I hope that this do not apply to you http://www.gocomics.com/peanuts/2000/01/04
Last edited on
Topic archived. No new replies allowed.