Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
110285 | 吴梓玄 | 18第一次出现与最后一次出现的位置 | C++ | Accepted | 1 MS | 272 KB | 314 | 2025-02-15 17:18:16 |
#include <bits/stdc++.h> using namespace std; int main() { int x,y,s=0,t,v; cin>>x; int a[x+5]; for(int i=1;i<=x;i++){ cin>>a[i]; } cin>>y; for(int i=1;i<=x;i++){ if(a[i]==y){ s=s+1; t=i; } } v=t-s+1; if(s!=0){ cout<<v<<' '<<t; } else{ cout<<-1; } return 0; }