Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
102686 饶晋吉 18第一次出现与最后一次出现的位置 C++ Accepted 1 MS 272 KB 377 2024-12-22 14:13:49

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 x,index=-1; cin>>x; for(int i=0;i<=n;i++){ if(a[i]==x){ if(index==-1){ cout<<i+1<<" "; } index=i; } } if(index==-1){ cout<<index<<" "; } else{ cout<<index+1; } return 0; }