Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
102635 朱安然 18第一次出现与最后一次出现的位置 C++ Accepted 1 MS 276 KB 379 2024-12-22 13:16:28

Tests(10/10):


Code:

#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<=n-1;i++){ cin>>a[i]; } int e; cin>>e; int index=-1; for(int i=0;i<=n-1;i++){ if(a[i]==e){ if(index==-1){ cout<<i+1<<" "; } index=i; } } if(index==-1){ cout<<-1; } else{ cout<<index+1; } return 0; }