Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
2365 | 吴奕希 | 18第一次出现与最后一次出现的位置 | C++ | Accepted | 1 MS | 276 KB | 592 | 2023-12-23 21:10:18 |
# include<iostream> using namespace std; int main() { int n,m; cin>>n; int lst[n], first=n, last=-1; for(int i = 0; i < n; i++) { cin>>lst[i]; } cin>>m; for(int i = 0; i < n; i++) { if(lst[i] == m) { if(i<first) { first=i; } if(i>last) { last=i; } } } if(first==n) { printf("-1"); } else { printf("%d %d", first+1, last+1); } return 0; }