Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
151997 卢语宸 18查找该数出现的位置 C++ Accepted 1 MS 276 KB 495 2026-04-19 14:17:41

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; int a[10000],b=0,c=0,w=0,e=0; int main() { int y=0; cin>>b; for(int i=1; i<=b; i++) { cin>>a[i]; } cin>>c; for(int i=1; i<=b; i++) { if(a[i]!=c) { y++; } if(y==b) { cout<<-1; return 0; } } for(int i=1; i<=b; i++) { w++; if(a[i]==c) { break; } } e=b; for(int i=b; i>=1; i--) { if(a[i]!=c) { e--; } if(a[i]==c) { break; } } cout<<w<<" "<<e; return 0; }