Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
116045 李朋秦 18第一次出现与最后一次出现的位置 C++ Accepted 2 MS 280 KB 332 2025-04-06 08:58:04

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; int main() { int a,b[2001],c,d=0; cin>>a; for(int i=1;i<=a;i++){ cin>>b[i]; } cin>>c; int i=1; while((b[i]!=c)&&(i<=a)){ i++; } if(i==a+1){ cout<<-1; return 0; } cout<<i<<" "; while((b[i]==c)&&(i<=a)){ i++; } cout<<i-1; return 0; }