Official

A - ^{-1} Editorial by en_translator


In order to solve this problem, check if \(P_i = X\) for each \(i = 1, 2, \ldots ,N\).
The “for each \(i = 1, 2, \ldots ,N\)” part can be achieved with a for statement, and the “if \(P_i = X\)” part can be expressed by a for statement.

Sample code (C++)

#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	for (int i = 0; i < n; i++) if (p[i] == x) cout << i + 1 << '\n';
}


Sample code (Python)

n, x = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
	if p[i] == x:
		print(i + 1)


Note that, unlike the Problem Statement, \(0\)-based indices are used in the sample codes above.

posted:
last update: