Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1415
- 10474 - Where is the Marble?
- """
- # test case counter
- count = 0
- while True:
- N, Q = map(int, input().split())
- if N + Q == 0:
- break
- nums = []
- queries = []
- for i in range(N):
- nums.append(int(input()))
- for i in range(Q):
- queries.append(int(input()))
- nums = sorted(nums)
- # test case incrementation and test case number
- count += 1
- print("CASE#", str(count) + ":")
- for i in range(Q):
- # setting the flag
- found = False
- # checking whether the queries are in the list
- hi = N - 1
- lo = 0
- while hi >= lo:
- mid = int((hi+lo)/2)
- if nums[mid] == queries[i]:
- print(queries[i], "found at", mid+1)
- found = True
- break
- elif nums[mid] > queries[i]:
- hi = mid -1
- else:
- lo = mid + 1
- # not found response
- if found is False:
- print(queries[i], "not found")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement