Exemple #1
0
int main()
{
    std::istream_iterator<int> in_iter(std::cin), eof;
    std::vector<int> vec;
    while (in_iter != eof)
        vec.push_back(*in_iter++);
    std::sort(vec.begin(), vec.end());
    std::copy(vec.cbegin(), vec.cend(), std::ostream_iterator<int>(std::cout, " "));
}
bool CInfiniteMediatorTest::filesEqual(std::string fname0, std::string fname1)
{
  std::ifstream filein(fname0.c_str());
  std::ifstream fileout(fname1.c_str());

  std::istream_iterator<char> end_of_stream;
  std::istream_iterator<char> in_iter(filein);
  std::istream_iterator<char> out_iter(fileout);

  return std::equal(in_iter,end_of_stream,out_iter);

}
Exemple #3
0
int main()
{
    std::istream_iterator<Sales_item> in_iter(std::cin), in_eof;
    std::vector<Sales_item> vec;
    
    while (in_iter != in_eof)
        vec.push_back(*in_iter++);
    sort(vec.begin(), vec.end(), compareIsbn);
    for (auto beg = vec.cbegin(), end = beg; beg != vec.cend(); beg = end) {
        end = find_if(beg, vec.cend(), [beg](const Sales_item &item){ return item.isbn() != beg->isbn(); });
        std::cout << std::accumulate(beg, end, Sales_item(beg->isbn())) << std::endl;
    }
}
Exemple #4
0
int main() {
    std::list<int> li;
    std::istream_iterator<int> in_iter(std::cin), in_eof;
    while (in_iter != in_eof)
        li.push_back(*in_iter++);

    auto lastZero = find(li.crbegin(), li.crend(), 0);
    if (lastZero != li.crend())
        std::cout << "0 exists!" << std::endl;
    else
        std::cout << "No 0 exists!" << std::endl;

    return 0;
}
int main() 
{
    // write one string per line to the standard output
    ostream_iterator<string> out_iter(cout, "\n");

    // read strings from standard input and the end iterator
    istream_iterator<string> in_iter(cin), eof;

    // read until eof and write what was read to the standard output
    while (in_iter != eof) 
	    // write value of in_iter to standard output
	    // and then increment the iterator to get the next value from cin
	    *out_iter++ = *in_iter++;  

    return 0;
}
Exemple #6
0
bool Median::tick2( const ArrayBase::Size &size )
{
  GET_OUTPUT_INIT( OUTPUT_OUT, out, T, size.getDims(), size.getCoords() );

  vector< T > buffer( m_n );
  vector< typename Array< T >::const_iterator > in_iter( m_n );

  for( index_t i=0; i<m_n; ++i )
  {
    GET_INPUT_AS_DIMS( INPUT_IN0+i, in_i, T, size.getDims() );
    in_iter[ i ] = in_i->begin();
  }

  const typename vector< T >::iterator buffer_begin = buffer.begin();
  const typename vector< T >::iterator buffer_end   = buffer.begin();
  const typename vector< T >::iterator buffer_nth   = buffer_begin + m_n/2;

  for(
    typename Array< T >::iterator
      out_iter( out->begin() )
    , out_end( out->end() )
    ; out_iter != out_end
    ; ++out_iter
    )
  {
    for( index_t i=0; i<m_n; ++i )
    {
      buffer[ i ] = (*in_iter[ i ]);
      ++in_iter[ i ];
    }

    nth_element( buffer_begin, buffer_nth, buffer_end );

    (*out_iter) = (*buffer_nth);
  }

  return true;
}
Exemple #7
0
int main(int argc, char *argv[])
{
#if defined(_WIN32) // && defined(_DEBUG)
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif


	if (argc != 4)
	{
		std::cerr << "Invalid number of arguments." << std::endl;
		std::cerr << "Usage: Huffman.exe -c/-u <infile> <outfile>" << std::endl;

		return 1;
	}

	std::ifstream in_file(argv[2], std::ios::in | std::ios::binary);
	if (!in_file)
	{
		std::cerr << "Couldn't open " << argv[2] << std::endl;
		return 2;
	}

	std::ofstream out_file(argv[3], std::ios::out | std::ios::binary | std::ios::trunc);
	if (!out_file)
	{
		std::cerr << "Couldn't open " << argv[3] << std::endl;
		return 3;
	}

	std::string arg(argv[1]);

	if (arg == "-c")
	{
		OFileBitstream stream(out_file);
		std::istreambuf_iterator<char> in_iter(in_file);

		std::cerr << "Construindo arvore..." << std::endl;
		Dictionary<unsigned char>* tree = build_huffman_tree(in_iter, std::istreambuf_iterator<char>());
		std::ifstream::pos_type size = in_file.tellg();
		in_file.seekg(0);
		std::cerr << "Comprimindo arquivo..." << std::endl;
		huffman_compress(tree, stream, in_iter, std::istreambuf_iterator<char>(), size);
		delete tree;
	} 
	else if (arg == "-u")
	{
		in_file.seekg(0, std::ios::end);
		unsigned long long size = in_file.tellg();
		in_file.seekg(0);

		IFileBitstream istream(in_file);
		std::cerr << "Lendo arvore..." << std::endl;
		Dictionary<unsigned char>* tree = readNode(istream);
		size -= in_file.tellg();
		std::cerr << "Descomprimindo arquivo..." << std::endl;
		huffman_uncompress(istream, out_file, tree, size);
		delete tree;
	}
	else if (arg == "--make-tree")
	{
		std::istreambuf_iterator<char> in_iter(in_file);

		Dictionary<unsigned char>* tree = build_huffman_tree(in_iter, std::istreambuf_iterator<char>());
		print_huffman_tree(tree, out_file);
		delete tree;
	}
	else if (arg == "--read-tree")
	{
		IFileBitstream istream(in_file);
		Dictionary<unsigned char>* tree = readNode(istream);
		print_huffman_tree(tree, out_file);
		delete tree;
	}

	out_file.close();
	in_file.close();


	return 0;
}
Exemple #8
0
int main ( )
{
#ifndef _RWSTD_STRICT_ANSI

    // use an extension of this implementation: NULL file name argument
    // creates a temporary file; closing the file stream object or its
    // associated filebuf removes the temporary file
    const char* const fname = 0;
    
#else   // if defined (_RWSTD_STRICT_ANSI)

    char fnamebuf [L_tmpnam];

    // create a temporary filename
    const char* const fname = std::tmpnam (fnamebuf);

    if (!fname)
        return 1;

#endif   // _RWSTD_STRICT_ANSI

    // create a filebuf object
    std::filebuf buf;

    // open the file and link it to the filebuf object
    buf.open (fname, std::ios::in | std::ios::out | std::ios::trunc);

    // create an ostreambuf_iterator and link it to 
    // the filebuf object
    std::ostreambuf_iterator<char, std::char_traits<char> > out_iter (&buf);

    const char charset[] =
        "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

    // output characters into the file using the ostreambuf_iterator
    for (unsigned i = 0; charset [i]; ++i)
        out_iter = charset [i];

    // seek to the beginning of the file
    buf.pubseekpos(0);
  
    // create an istreambuf_iterator and link it to  the filebuf object
    std::istreambuf_iterator<char, std::char_traits<char> > in_iter (&buf);

    // construct an end of stream iterator
    std::istreambuf_iterator<char, std::char_traits<char> > end;

    std::cout << '\n';

    // output the contents of the file
    while (!in_iter.equal (end))
        std::cout << *in_iter++;

    std::cout << '\n';

    if (fname) {
        // close the stream before removing the file
        buf.close ();

        // remove the temporary file (must have a name)
        std::remove (fname);
    }

    return 0;
}
Exemple #9
0
Chart::Chart(const std::string& fileName) {
    std::ifstream fin(fileName, std::ios_base::binary);
    std::istream_iterator<Point> in_iter(fin), eof;
    std::copy(in_iter, eof, std::back_inserter(pointList));
}