Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
2413 邓小龙 18第一次出现与最后一次出现的位置 C++ Accepted 0 MS 272 KB 592 2024-01-06 12:42:49

Tests(10/10):


Code:

# 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; }