| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 151924 | 令狐文丽 | 18第一次出现与最后一次出现的位置 | C++ | Accepted | 1 MS | 276 KB | 468 | 2026-04-19 12:17:37 |
#include<bits/stdc++.h>//万能头//iostream using namespace std; int main() { //两个for第一次 最后一次出现 int n,x,l=-1,r=-1;//x要找的这个数 cin>>n; int a[n+1]; for(int i =1;i<=n;i++){ cin>>a[i]; } cin>>x; for(int i =1;i<=n;i++){ if(x==a[i]){ l=i; break; } } for(int i =n;i>=1;i--){ if(x==a[i]){ r=i; break; } } if(l==-1){ cout<<-1; }else{ cout<<l<<" "<<r; } return 0; }