fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n, target;
  5. scanf("%d", &n);
  6.  
  7. int nums[n];
  8. for (int i = 0; i < n; i++) scanf("%d", &nums[i]);
  9.  
  10. scanf("%d", &target);
  11.  
  12. int first = -1, last = -1;
  13.  
  14. for (int i = 0; i < n; i++) {
  15. if (nums[i] == target) {
  16. if (first == -1) first = i;
  17. last = i;
  18. }
  19. }
  20.  
  21. printf("%d %d", first, last);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5316KB
stdin
6
5 7 7 8 8 10
8
stdout
3 4