Beispiel #1
0
void copy_out(array<T, S>& out, const array<J, D>& in)
{
	CHECK(out.length() <= in.length(), erange);
	typename array<J, D>::const_iterator it_src = in.begin();
	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end) *it++ = *it_src++;
}
Beispiel #2
0
void anagram(array<string,sz> &arrStr){
//	for_each( arrStr.begin(), arrStr.end(), myStrSort);
	for( auto & str : arrStr )
		sort( str.begin(), str.end() );
	sort( arrStr.begin(), arrStr.end() );

	std::cout << "\nAfter in-place sorting, arrStr contains:\n\n";
	for ( auto it = arrStr.begin(); it != arrStr.end(); ++it )
		std::cout << ' ' << *it;
	std::cout << endl;
}
Beispiel #3
0
static void con_add_buffer_line(const con_priority priority, const char *const buffer, const size_t len)
{
	/* shift con_buffer for one line */
	std::move(std::next(con_buffer.begin()), con_buffer.end(), con_buffer.begin());
	console_buffer &c = con_buffer.back();
	c.priority=priority;

	size_t copy = std::min(len, CON_LINE_LENGTH - 1);
	c.line[copy] = 0;
	memcpy(&c.line,buffer, copy);
}
Beispiel #4
0
void copy_n(array<T, S>& out, const array<J, D>& in, int n)
{
	/* TODO: would be nice
	CHECK(out.length() <= in.length(), erange);
	loops::loop_n<loops::assign_copy_class<T, J> >
		(out.derived(), in.derived(), n);
	*/
	typename array<J, D>::const_iterator it_src = in.begin();
	typename array<T, S>::iterator it = out.begin();

	while (n--) *it++ = *it_src++;
}
Beispiel #5
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    array<T,3> x = {{ 1, 2, 3 }};
    array<T,3> y = {{ 4, 5, 6 }};
    blas::swap(x.size(), x.c_array(), 1, y.c_array(), 1);

    const array<T,3> x_expected = {{ 4, 5, 6 }};
    const array<T,3> y_expected = {{ 1, 2, 3 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            x.begin(), x.end(), x_expected.begin(), x_expected.end());
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), y_expected.begin(), y_expected.end());
}
Beispiel #6
0
bool name_copy(array<u8>& d, const char* s) {
	const char* p = s;
	const char* e = sz_find_last_or_end(s, '.');

	if (!d.set_size(e - s + 1))
		return false;

	memcpy(d.begin(), s, e - s);
	d[e - s] = '\0';

	_strlwr_s((char*)d.begin(), d.size());

	return true;
}
Beispiel #7
0
int main() {
	size_t tCase;
	int tmp;
	in >> tCase;
	while (tCase--) {
		MaxResult = 0;
		SequenceNumber.clear();
		fill(DynamicMemory.begin(), DynamicMemory.end(), -1);
		in >> Seqnum;
		for (size_t i = 0; i < Seqnum;i ++) {
			in >> tmp;
			SequenceNumber.push_back(tmp);
		}
		for (size_t i = 0; i < Seqnum; i++) {
			if (DynamicMemory[i] == -1) LIS(SequenceNumber, i);
		}
		for (size_t i = 0; i < Seqnum; i++) {
			if (DynamicMemory[i] == -1) break;
			if (DynamicMemory[i] > MaxResult) {
				MaxResult = DynamicMemory[i];
			}
		}
		cout << MaxResult << endl;
	}

	return 0;
}
/** Evaluates and executes a dvisvgm special statement.
 *  @param[in] prefix special prefix read by the SpecialManager
 *  @param[in] is the special statement is read from this stream
 *  @param[in] actions object providing the actions that can be performed by the SpecialHandler */
bool DvisvgmSpecialHandler::process (const string &prefix, istream &is, SpecialActions &actions) {
	struct Command {
		const char *name;
		void (DvisvgmSpecialHandler::*handler)(InputReader&, SpecialActions&);
	};
	constexpr array<Command, 7> commands {{
		{"raw",       &DvisvgmSpecialHandler::processRaw},
		{"rawdef",    &DvisvgmSpecialHandler::processRawDef},
		{"rawset",    &DvisvgmSpecialHandler::processRawSet},
		{"endrawset", &DvisvgmSpecialHandler::processEndRawSet},
		{"rawput",    &DvisvgmSpecialHandler::processRawPut},
		{"bbox",      &DvisvgmSpecialHandler::processBBox},
		{"img",       &DvisvgmSpecialHandler::processImg}
	}};
	StreamInputReader ir(is);
	const string cmdstr = ir.getWord();
	auto it = find_if(commands.begin(), commands.end(), [&](const Command &cmd) {
		return cmd.name == cmdstr;
	});
	if (it != commands.end()) {
		ir.skipSpace();
		(this->*it->handler)(ir, actions);
	}
	return true;
}
Beispiel #9
0
int main() {
    int N, M, total=0;
    
    cin >> N >> M;
    //scanf("%d %d", &N, &M);
    fill_n(childSize.begin(), N+1, 1);
    while (M--) {
        int from, to;
        
        cin >> from >> to;
        //scanf("%d %d", &from, &to);
        if (from < to) {
            int temp = from;
            from = to;
            to = temp;
        }
        tree[from].push_back(to);
    }
    
    for (int i=N; i!=0; i--) {
        update(i);
    }
    
    for (int i=N; i!=0; i--) {
        if (0 == childSize[i]%2) {
            total += tree[i].size();
            seperate(i);
        }    
    }
    
    cout << total << endl;

    return 0;
}
Beispiel #10
0
void copy(array<T, S>& out, const T& val,
		types::term as_element)
{
	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end)
		*(it++) = (val);
}
Beispiel #11
0
void buildSuffixArray()
{
  layout = 0;
  for (int i = 0; i < n; i++)
    order[i] = n - 1 - i;

  stable_sort(order.begin(), order.begin() + n, [&] (int a, int b) { return s[a] < s[b]; });

  for (int i = 0; i < n; i++)
    {
      sufArray[layout][i] = order[i];
      classes[i] = s[i];
    }

  for (int len = 1; len < n; len *= 2)
    {

      for (int i = 0; i < n; tempClasses[i] = classes[i], i++);
      for (int i = 0; i < n; i++)
        {
          classes[sufArray[layout][i]] = i > 0 &&
              tempClasses[sufArray[layout][i - 1]] == tempClasses[sufArray[layout][i]] &&
              sufArray[layout][i - 1] + len < n &&
              tempClasses[sufArray[layout][i - 1] + len / 2] == tempClasses[sufArray[layout][i] + len / 2] ?
                classes[sufArray[layout][i - 1]] : i;
        }


      for (int i = 0; i < n; i++)
        {
          counter[i] = i;
          sufArray[layout + 1][i] = sufArray[layout][i];
        }

      for (int i = 0; i < n; i++)
        {
          int s1 = sufArray[layout][i] - len;
          if (s1 >= 0)
              sufArray[layout + 1][counter[classes[s1]]++] = s1;

        }
      layout++;
    }
}
Beispiel #12
0
    void stop() {
        if ( !started_) return;
        started_ = false;
        sock_.close();

        ptr self = shared_from_this();
        array::iterator it = std::find(clients.begin(), clients.end(), self);
        clients.erase(it);
        update_clients_changed();
    }
Beispiel #13
0
void copy(array<T, S>& out, const J* it_src)
{
	CHECK(it_src != NULL, einvalid);

	typename array<T, S>::iterator it_end = out.end();
	typename array<T, S>::iterator it = out.begin();

	while (it != it_end)
		*it++ = cast<T>(*it_src++);
}
Beispiel #14
0
		bool operator==(const array& _ar)const{
			if(size()!=_ar.size())return false;
			iterator itr1=begin(),itr2=_ar.begin();
			while(itr1!=end()){
				if((*itr1)!=(*itr2))return false;
				++itr1;
				++itr2;
			}
			return true;
		}
Beispiel #15
0
		void copy(const array<T>& _ar){
			assign(_ar.size());
			const_iterator citr=_ar.begin(),cenditr=_ar.end();
			iterator itr=begin();
			while(citr!=cenditr){
				(*itr)=(*citr);
				++citr;
				++itr;
			}
		}
Beispiel #16
0
int main(int argc, char** argv)
{
	std::cout << "arrStr contains:\n";
	for ( auto it = arrStr.begin(); it != arrStr.end(); ++it )
		std::cout << ' ' << *it;
	std::cout << '\n';
	sortAnagram(arrStr);
	anagram(arrStr);

    return 0;
}
Beispiel #17
0
bool fgame::winningsets(array<char*, 3> k) {
	array<char*, 3>::iterator creator; //instantiating the iterator named creator
	creator = k.begin(); //allows me to iterate through the winning set to make sure that a win is triggered correctly
	if (**creator == **(creator + 1) && **(creator + 1) == **(creator + 2)) { //pointer creation
		return true;
	}

	else {
		return false; //will return as not a win
	}
}
Beispiel #18
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    { // Contiguous
        array<T,3> x = {{ 1, 2, 3 }};
        blas::scal(x.size(), 2, x.c_array(), 1);

        const array<T,3> x_expected = {{ 2, 4, 6 }};
        BOOST_CHECK_EQUAL_COLLECTIONS(
                x.begin(), x.end(), x_expected.begin(), x_expected.end());
    }

    { // Strided
        array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
        const long inc = 2;
        blas::scal(x.size()/inc, 2, x.c_array(), inc);

        const array<T,6> x_expected = {{ 2, -1, 4, -1, 6, -1 }};
        BOOST_CHECK_EQUAL_COLLECTIONS(
                x.begin(), x.end(), x_expected.begin(), x_expected.end());
    }
}
Beispiel #19
0
    int main(std::string __name__) {
        sub::main("sub");
        #define sub SUB
        sub2::main("sub2");
        _var_a_ = (array<int, 2>){2, 3};
        b = std::vector<int>(_var_a_.begin(), _var_a_.end());
        _var_b_ = (array<array<int, 2>, 2>){ 4, 5 ,  6, 7 };
        c = std::vector<array<int, 2> >(_var_b_.begin(), _var_b_.end());
        _var_c_ = (array<int, 2>){9, 10};
        d = (_type_a_){8, std::vector<int>(_var_c_.begin(), _var_c_.end())};
        _var_d_ = (array<_type_a_, 2>){d, d};
        e = std::vector<_type_a_>(_var_d_.begin(), _var_d_.end());
        _var_e_ = (array<int, 2>){1, 2};
        _var_f_ = std::vector<int>(_var_e_.begin(), _var_e_.end());
        f = _var_f_[0];
        g = _var_f_[1];
        _var_g_ = (array<int, 2>){3, 4};
        _var_h_ = (_type_b_){std::vector<int>(_var_g_.begin(), _var_g_.end()), 5};
        h = _var_h_._0;
        i = _var_h_._1;
        _var_i_ = (_type_b_){h, i};
        _var_j_ = _var_i_._0;
        j = _var_j_[0];
        k = _var_j_[1];
        m = _var_i_._1;
        fun(0);
        #undef SUB

        return 0;
    }
Beispiel #20
0
int main()
{
	int tests;
	int citiesN;
	int relationsN;
	int paths;
	string name;
	cin >> tests;

	for (int t = 0; t < tests; t++)
	{
		cityId.clear();
		graph.clear();
		cin >> citiesN;
		for(int c = 1; c <= citiesN; c++)
		{
			distances[c] = infinity;
			emptyDistances[c] = infinity;

			city city;
			cin >> city.name;
			graph[c] = city;
			cityId[city.name] = c;
			cin >> relationsN;

			for(int r = 0; r < relationsN; r++)
			{
				way way1;
				cin >> way1.destination >> way1.cost;
				graph[c].adjacent.push_back(way1);
				way way2 = way1;
				way2.destination = c;
				graph[way2.destination].adjacent.push_back(way2);
			}

		}

		cin >> paths;

		for (int p = 0; p < paths; p++)
		{
			string source, destination;
			cin >> source >> destination;
			distances = emptyDistances;
			fill(visited.begin(), visited.end(), false);
			dijkstra(cityId[source], cityId[destination]);
			cout << distances[cityId[destination]] << endl;
		}
	}
	
	return 0;
}
Beispiel #21
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{   1, -555,   2, -555,   3, -555 }};
    array<T,3> y       = {{ 555,  555, 555 }};
    const long incx = 2, incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::copy(x.size()/incx, x.data(), incx, y.c_array(), incy);

    const array<T,3> expected = {{ 1, 2, 3 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Beispiel #22
0
void sort_edges(array<iPair,4>& marker) {
  /* y has the lowest y-coordinate (top left), stick it
     at the end of the list */
  sort(marker.begin(), marker.end()
       , [](const iPair &a, const iPair &b) {
	 return a.y > b.y;
       });

  /* Sorting green blobs - if marker[0] has a greater X value,
   * it's not the origin so swap it around */
  if(marker[0].x > marker[1].x) swap(marker[0], marker[1]);
  if(marker[2].x > marker[3].x) swap(marker[2], marker[3]);
}
Beispiel #23
0
    __agency_exec_check_disable__
    __AGENCY_ANNOTATION
    array(const array& other)
      : array(other.shape())
    {
      auto iter = other.begin();
      auto result = begin();

      for(; iter != other.end(); ++iter, ++result)
      {
        *result = *iter;
      }
    }
Beispiel #24
0
BOOST_AUTO_TEST_CASE_TEMPLATE( real_valued, T, real_types )
{
    const array<T,6> x = {{ 1, -1, 2, -1, 3, -1 }};
    const long incx = 2;
    array<T,3> y = {{ 4, 5, 6 }};
    const int incy = 1;

    BOOST_REQUIRE_EQUAL(x.size()/incx, y.size()/incy);
    blas::axpby(x.size()/incx, 3, x.data(), incx, 7, y.c_array(), incy);

    const array<T,3> expected = {{ 1*3+7*4, 2*3+7*5, 3*3+7*6 }};
    BOOST_CHECK_EQUAL_COLLECTIONS(
            y.begin(), y.end(), expected.begin(), expected.end());
}
Beispiel #25
0
static void readDouble(const File& file,
                       const string& name,
                       const array<size_t, dimension>& start,
                       const array<size_t, dimension>& count,
                       Type* values,
                       PropertyType Type::*property,
                       const Converter& converter) {
    size_t size = accumulate(count.begin(), count.end(), 1, [](size_t n, size_t m) { return n*m; });
    vector<double> v(size);
    const Var var(file.var(name));
    var.get(start, count, v.data());
    size_t n = 0;
    for (auto it = v.begin(); it != v.end(); ++it, ++n) {
        values[n].*property = converter(*it);
    }
}
Beispiel #26
0
int main() {
	size_t tCase;
	in >> tCase;
	while (tCase--) {
		fill(DynamicMemory.begin(), DynamicMemory.end(), 0);
		vector<int> Triangle(1, 1);
		in >> TriCount;
		Triangle[0] = TriCount;
		int TotalNum = SumSigma(TriCount);
		for (int i = 1; i <= TotalNum; i++) {
			in >> TriCount;
			Triangle.push_back(TriCount);
		}
		out << TRIPATHCNT(Triangle, TotalNum) << endl;
	}
}
Beispiel #27
0
int main() {
	size_t tCase;
	in >> tCase;
	while (tCase--) {
#ifdef LOCAL
		tstart = NowTime();
#endif
		fill(DynamicMemory.begin(), DynamicMemory.end(), -1);
		in >> PINumbers;
		out << PI(PINumbers) << endl;
#ifdef LOCAL
		tend = NowTime();
		out << "Operating time: " << chrono::duration_cast<std::chrono::milliseconds>(tend - tstart).count() << endl;
#endif
	}
	return 0;
}
  /** \brief Create a structured cube grid

      \param lowerLeft  Lower left corner of the grid
      \param upperRight Upper right corner of the grid
      \param elements   Number of elements in each coordinate direction

      \note YaspGrid only supports lowerLeft at the origin.  This
            function throws a GridError if this requirement is not met.
  */
  static std::unique_ptr<GridType>
  createCubeGrid(const FieldVector<ctype, dimworld> &lowerLeft,
                 const FieldVector<ctype, dimworld> &upperRight,
                 const array<int, dim> &elements) {
    for (int d = 0; d < dimworld; ++d)
      if (std::abs(lowerLeft[d]) > std::abs(upperRight[d]) * 1e-10)
        DUNE_THROW(GridError,
                   className<BemppStructuredGridFactory>()
                       << "::createCubeGrid(): The lower coordinates "
                          "must be at the origin for YaspGrid.");

    FieldVector<int, dim> elements_;
    std::copy(elements.begin(), elements.end(), elements_.begin());

    return std::unique_ptr<GridType>(
        new GridType(upperRight, elements_, FieldVector<bool, dim>(false), 0));
  }
Beispiel #29
0
    __AGENCY_ANNOTATION
    friend bool operator==(const array& lhs, const Range& rhs)
    {
      if(lhs.size() != rhs.size()) return false;

      auto i = lhs.begin();
      auto j = rhs.begin();

      for(; i != lhs.end(); ++i, ++j)
      {
        if(*i != *j)
        {
          return false;
        }
      }

      return true;
    }
Beispiel #30
0
		void clear(){
			Data[0].front=&Data[0];
			Data[0].back=&Data[0];
			if(Data.size()==1){
				Ptrs.clear();
				return;
			}else{
				Ptrs.assign(Data.size()-1,0);
				std::deque<Datum*>::iterator itr=Ptrs.begin(),enditr=Ptrs.end();
				array<Datum>::iterator ditr=Data.begin();
				++ditr;	//Nullデータ部をよける
				while(itr!=enditr){
					(*itr)=&(*ditr);
					++ditr;
					++itr;
				}
			}
		}