Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
97003 邹昊辰 18查找该数出现的位置 C++ Accepted 1 MS 280 KB 395 2024-11-10 10:37:46

Tests(10/10):


Code:

#include<iostream> using namespace std; int main(){ int n,a[2000],m,first=-1,last=-1; 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){ first=i; break; } } for(int i=n;i>=1;i--){ if(a[i]==m){ last=i; break; } } if(first==-1)cout<<-1; else cout<<first<<" "<<last; return 0; }