// zadatak 1 - 20061113

#include <iostream>

#include <vector>
#include <string>
#include <list>

#include <algorithm>

#include <iterator>

using namespace std;

int uvjet( const float &f){
  return (f>=5.0);
}

int uvjet2( const string &str){
  return (str.size()==1 || str.size()==2);
}

int main(){

  vector<float> vf;
  vector<string> vs;
  
  vf.push_back(7.2);
  vf.push_back(2.5);
  vf.push_back(2.5);
  vf.push_back(8.7);
  
  vs.push_back("a");
  vs.push_back("x");
  vs.push_back("a");
  vs.push_back("a");
  vs.push_back("ba");
  
  cout << count(vf.begin(), vf.end(), 2.5) << endl;
  cout << count(vs.begin(), vs.end(), "a") << endl;
  
  // broji koliko ima floatova koji su >= 5.0
  cout << count_if(vf.begin(), vf.end(), uvjet) << endl;
  
  // broji koliko ima stringova duljina 1 ili 2
  cout << count_if(vs.begin(), vs.end(), uvjet2) << endl;
  
  // pronadji prvi "x" u vs-u
  vector<string>::iterator its;
  if( (its=find(vs.begin(), vs.end(), "x")) != vs.end() ){
    cout << *its << " postoji." << endl;
  }
  else{
    cout << "Ne postoji." << endl;
  }
  
  // pronadji prvi broj u vf-u koji je veci od 5.0
  vector<float>::iterator itf;
  if( (itf=find_if(vf.begin(), vf.end(), uvjet)) != vf.end() ){
    cout << "Broj veci od pet postoji (u vektoru)." << endl;
  }
  else{ 
    cout << "Broj veci od pet ne postoji (u vektoru)." << endl;
  }
  
  // sortira vector stringa
  sort(vs.begin(), vs.end());
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  // vraca iterator na pocetak duplikata
  vector<string>::iterator kraj=unique(vs.begin(), vs.end());
  cout << endl;
  for( its=vs.begin(); its!=kraj; ++its){
    cout << "vs: " << *its << endl;
  }
  
  // okreni vektor
  reverse( vs.begin(), vs.end() );
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  // zamjeni sve stringove "a" sa stringom "xyz"
  replace(vs.begin(), vs.end(), string("a"), string("xyz") );
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  // napuni cijeli vektor sa stringovima "bla"
  fill(vs.begin(), vs.end(), string("bla"));
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  // napuni prva tri elementa stringovima "ajde"
  fill_n(vs.begin(), 3, string("ajde"));
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  /*
  // uporabom ovakvog koda program ce se srusiti  
  
  fill_n(vs.begin(), 300, string("bla"));
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  } 
  */
  
  // zahtjeva: #include <iterator>
  fill_n(back_inserter(vs), 10, string("ABC"));
  cout << endl;
  for( its=vs.begin(); its!=vs.end(); ++its){
    cout << "vs: " << *its << endl;
  }
  
  return 0;
}


