Untitled
unknown
plain_text
5 months ago
536 B
3
Indexable
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n--) { int a, b, k = 10000, pos; cin >> a >> b; int arr[a]; for (int i = 0; i < a;i++) { cin >> arr[i]; } for (int i = 0; i < a;i++) { if(abs(b-arr[i])<k) { k = abs(b - arr[i]); pos = i + 1; } } cout << pos << "\n"; } }
Editor is loading...
Leave a Comment