Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
5052 | 邓小龙 | 18第一次出现与最后一次出现的位置 | C++ | Accepted | 1 MS | 276 KB | 585 | 2024-11-01 17:22:38 |
#include<iostream> // cin\cout\endl #include<cstdio> //scanf()\printf() #include<cstring> // strcpy()\strcat()\strcmp()\strlen()\memset() #include<cmath> //sqrt()\pow()\abs()\ceil()\floor()\max()\min() using namespace std; int main(){ int a[2001]; int x,n,first=-1,last=-1; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; cin>>x; for(int i=1;i<=n;i++){ if(a[i]==x&&first==-1) first=i; if(a[i]==x) last = i; } if(first==-1) cout<<-1<<endl; else cout<<first<<" "<<last<<endl; return 0; }