Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
96240 邹昊辰 18第一次出现与最后一次出现的位置 C++ Accepted 1 MS 280 KB 391 2024-11-03 14:15:25

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; }