Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
90147 | 任斌 | 18查找该数出现的位置 | C++ | Accepted | 1 MS | 284 KB | 373 | 2024-09-08 09:26:18 |
#include<bits/stdc++.h> using namespace std; int main() { int n,a[2001],m,t1=0,t2=0; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cin>>m; for(int i=1;i<=n;i++){ if(a[i]==m){ t1=i; break; } } for(int i=n;i>=1;i--){ if(a[i]==m){ t2=i; break; } } if(t1==0) cout<<-1; else cout<<t1<<" "<<t2<<endl; return 0; }