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,ret,j=0;
  7. ret=-1;
  8.  
  9. for(i=0; i<n; i++){
  10. if(a[i]==x){
  11. j+=1;
  12. }
  13. }
  14. return j;
  15. }
  16.  
  17. int main(void) {
  18. int n,x,i;
  19. int *a;
  20. int ans = -1;
  21. scanf("%d %d",&n,&x);
  22. a = (int*)malloc(sizeof(int)*n);
  23. if(a==NULL){
  24. printf("ERROR\n");
  25. return -1;
  26. }
  27. for(i=0;i<n;i++){
  28. scanf("%d",&a[i]);
  29. }
  30. ans = linear_search(a,n,x);
  31. if(ans != 0) printf("Found_%d_%ds\n",ans,x);
  32. else printf("not found\n");
  33. free(a);
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5276KB
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