Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
96238 | 王珠潏 | 18第一次出现与最后一次出现的位置 | C++ | Accepted | 1 MS | 280 KB | 389 | 2024-11-03 14:11:02 |
#include<iostream> using namespace std; int main() { int a[2000],n,m,first=-1,lest=-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(m==a[i]){ lest=i; break; } } if(first==-1){ cout<<-1; }else{ cout<<first<<" "<<lest; } return 0; }