#C3061. Find the Index of a Number in a List
Find the Index of a Number in a List
Find the Index of a Number in a List
Given a target number and a list of integers, your task is to determine whether the number exists in the list. If it exists, output the index of its first occurrence; otherwise, indicate that the number is not in the list.
Formally, let \(L = [a_0, a_1, \ldots, a_{n-1}]\) be the list and \(x\) be the number to search. You need to find the smallest index \(i\) such that \(a_i = x\). If no such index exists, output that \(x\) is not in the list.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains a single integer, representing the target number \(x\).
- The second line contains a list of space-separated integers \(a_0, a_1, \ldots, a_{n-1}\) in which the search is performed.
outputFormat
Output a single line to standard output (stdout) in one of the following formats:
- If the target number \(x\) is found in the list at index \(i\), output:
\(x\) is at index \(i\)
. - If the target number \(x\) is not in the list, output:
\(x\) is not in the list
.
34
10 20 34 45 56
34 is at index 2