I like crazy, and I found that if you really use STL functions like fish, you can basically save a lot of things...
When I went to class C ++ a few days ago, I thought this function was very interesting. Now I am using it very conveniently ,,,
Let's talk about the count_if function first. I think that all the comparable functions you can write can be found for you, my days, And, doesn't it save a lot of time?
# Include <stdio. h> # include <string. h> # include <stdlib. h> # include <math. h >#include <iostream >#include <algorithm> using namespace STD; int A [111]; bool CMP (int A) {if (a <0) return true; elsereturn false;} // you can set the CMP function on your own. This is too convenient. ...int main () {int N; while (scanf ("% d ", & N )! = EOF) {for (INT I = 0; I <n; I ++) scanf ("% d", & A [I]); int n = count_if (, A + N, CMP); printf ("% d \ n", n);} return 0 ;}
Count Function
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <iostream>#include <algorithm>using namespace std;int a[11];int main(){for(int i=0;i<10;i++)scanf("%d",&a[i]);int n=count(a,a+10,1);printf("%d\n",n);return 0;}