Find the first non-repeated integer in this file .
In the sequence {1, 7, 3, 1, 4, 3}, the answer would be 7 . 7 and 4 are the only non-repeated integers; of these 7 appears first.
Click here to open the file.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
1 2 3 4 5 6 7 |
|
In pascal:
uses crt; var a:array[1..200]of integer; f:text; const fi=’TEST.TXT’; procedure input; var i:byte; begin assign(f,fi); reset(f); for i:=1 to 200 do readln(f,a[i]); end; procedure output; var i,v:byte; begin for i:=1 to 199 do begin v:=i+1; while a[i]<>a[v] do begin v:=v+1; if v=200 then begin writeln(a[i]);exit;end; end; end; end; begin clrscr; input; output; readln; end.
Show the answer: 25.
CTRL+F on any browser and search number by number. It's pretty easy because the answer is the second appearance on the list...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
A better way of doing it, IMO.
Although I'm not averse to using computer time rather than my own time for solving problems I would like to point out that using count on every element of the list uses computer time unnecessarily. Better to count the number of occurences of each item in the list first. There's a class in the standard Python collections module that makes this easy to do.
Problem Loading...
Note Loading...
Set Loading...
Here is the number list from the text file:
And here is the code that finds the required number. I think it is fairly easy to understand