|
|
back to boardSTL question I Wonder why I have to sort in advance the elements in the array of the teacher in order to use binary_search otherwise I get WA Re: STL question I have use STL and had WA1 too. But I use count(). Here is my code in C++ #pragma comment(linker, "/STACK:16777216") #include <iostream> #include <algorithm> using namespace std; void main() { int v[15000],s[1000000],z=0,i,j,n,st; cin>>n; for (i = 0; i <=n-1; i++) cin>>v[i]; cin>>st; for (i = 0; i <=st-1; i++) cin>>s[i]; for (i = 0; i <=st-1; i++) z+=count(s,s+st,v[i]); cout<<z; } what's wrong? Re: STL question I use binary search and now I have WA2 :) Help me please! #include <iostream> #include <algorithm> using namespace std; void main() { int v[15000],s,z=0,i,j,n,st,t; cin>>n; for (i = 0; i <=n-1; i++) {cin>>t;if (t!=v[i-1]) v[i]=t; } cin>>st; for (i = 0; i <=st-1; i++) {cin>>s; if(binary_search(v,v+n,s)==true)z++; } cout<<z; } Edited by author 18.02.2007 03:01 |
|
|