fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //線形探索
  5. int linear_search(int a[],int n,int x){
  6. int i,count=0,ret=-1;
  7. for(i=0;i<n;i++){
  8. if(a[i]==x){
  9. ret=i;
  10. count++;
  11. }
  12. }return count;
  13. }
  14.  
  15. int main(void) {
  16. int n,x,i;
  17. int *a;
  18. int ans = -1;
  19. scanf("%d %d",&n,&x);
  20. a = (int*)malloc(sizeof(int)*n);
  21. if(a==NULL){
  22. printf("ERROR\n");
  23. return -1;
  24. }
  25. for(i=0;i<n;i++){
  26. scanf("%d",&a[i]);
  27. }
  28. ans = linear_search(a,n,x);
  29. if(ans != 0) printf("Found_%d_%ds\n",ans,x);
  30. else printf("not found\n");
  31. free(a);
  32. return 0;
  33. }
Success #stdin #stdout 0s 5284KB
stdin
50 5
12	3	4	12	11	5	7	15	18	0	0	5	10	6	15	6	4	10	8	16	12	9	10	11	12	9	5	7	10	14	3	17	11	10	7	15	5	2	6	3	19	7	8	16	13	3	18	10	19	5
stdout
Found_5_5s