// string toolkit
static inline void split(std::string src, const char* token, strArray& vect)
{
    int nend=0;
    int nbegin=0;
    while(nend != -1)
    {
        nend = src.find(token, nbegin);
        if(nend == -1)
            vect.push_back(src.substr(nbegin, src.length()-nbegin));
        else
            vect.push_back(src.substr(nbegin, nend-nbegin));
        nbegin = nend + strlen(token);
    }
}
Esempio n. 2
0
// string toolkit
static inline void split(const std::string& src, const std::string& token, strArray& vect)
{
    size_t nend = 0;
    size_t nbegin = 0;
    size_t tokenSize = token.size();
    while(nend != std::string::npos)
    {
        nend = src.find(token, nbegin);
        if(nend == std::string::npos)
            vect.push_back(src.substr(nbegin, src.length()-nbegin));
        else
            vect.push_back(src.substr(nbegin, nend-nbegin));
        nbegin = nend + tokenSize;
    }
}
Esempio n. 3
0
File: P030.cpp Progetto: kyokey/MIPT
void mult(strArray &a, strArray &b)
{
	strArray c(a); a.clear();
	for (int i = 0; i < c.size(); i ++)
		for (int j = 0; j < b.size(); j ++)
			a.push_back(c[i] + b[j]);
};
Esempio n. 4
0
// string toolkit
static KDvoid split ( std::string sString, const KDchar* szToken, strArray& vStrings )
{
	KDint  nEnd   = 0;
	KDint  nBegin = 0;

	while ( nEnd != -1 )
	{
		nEnd = sString.find ( szToken, nBegin );

		if ( nEnd == -1 )
		{
			vStrings.push_back ( sString.substr ( nBegin, sString.length ( ) - nBegin ) );
		}
		else
		{
			vStrings.push_back ( sString.substr ( nBegin, nEnd - nBegin ) );
		}

		nBegin = nEnd + kdStrlen ( szToken );
	}
}
Esempio n. 5
0
File: P030.cpp Progetto: kyokey/MIPT
bool trans(int l, int r, strArray &a)
{
	int i = l, ope = 1, j;
	strArray b, c, d;
	string s;
	a.clear();	
	if (l > r) {
		a.push_back("");
		return 1;
	};
	while (i <= r)
	{
		if (st[i] == '+')
		{
			if (ope) return 0;
			ope = 1; ++i;
		} 
		else {
			if (!ope || (st[i] < 'a' || st[i] > 'z') && st[i] != '(') return 0;
			b.clear(); b.push_back("");
			while (i <= r && (st[i] >= 'a' && st[i] <= 'z' || st[i] == '(')) 
			{
				if (st[i] == '(')
				{
					if (!findEnd(i, j, r)) return 0;
					if (!trans(i + 1, j - 1, c)) return 0;
					i = j + 1;
				}
				else {
					s = "";
					while (i <= r && st[i] >= 'a' && st[i] <= 'z') s += st[i ++];
					c.clear(); c.push_back(s);
				};
				if (c.empty()) return 0;
				mult(b, c);
			};
			if (b.size() == 1 && b[0] == "") continue;
			add(a, b); ope = 0;
		};
	};
	if (ope && !a.empty()) return 0;
	return 1;
};
Esempio n. 6
0
File: P030.cpp Progetto: kyokey/MIPT
void add(strArray &a, const strArray &b)
{
	for (int i = 0; i < b.size(); i ++)
		a.push_back(b[i]);
};