ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

STL question
Posted by Todor Tsonkov 7 Jul 2006 15:31
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
Posted by IvanPMI_LNU 17 Feb 2007 23:45
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
Posted by IvanPMI_LNU 17 Feb 2007 23:45
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