예제 #1
0
파일: P030.cpp 프로젝트: 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]);
};
예제 #2
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
// 首先,判断表格的字符串是否为{x,y}
// 是,则使用分裂字符串到参数strs
// 否则参数strs为空;
// 表格是对的,则返回true
static bool splitWithForm(const char* pStr, strArray& strs)
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(!pStr);

        // string is empty
        // 字符串为空
        std::string content = pStr;
        CC_BREAK_IF(content.length() == 0);

        int nPosLeft  = content.find('{');
        int nPosRight = content.find('}');

        // don't have '{' and '}'
        // 不含有{}
        CC_BREAK_IF(nPosLeft == (int)std::string::npos || nPosRight == (int)std::string::npos);
        // '}' is before '{'
        // }在{前
        CC_BREAK_IF(nPosLeft > nPosRight);

        std::string pointStr = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1);
        // nothing between '{' and '}'
        // 在{}之前没有任何参数
        CC_BREAK_IF(pointStr.length() == 0);

        int nPos1 = pointStr.find('{');
        int nPos2 = pointStr.find('}');
        // contain '{' or '}' 
        // 包含{}
        CC_BREAK_IF(nPos1 != (int)std::string::npos || nPos2 != (int)std::string::npos);

        split(pointStr, ",", strs);
        if (strs.size() != 2 || strs[0].length() == 0 || strs[1].length() == 0)
        {
            strs.clear();
            break;
        }

        bRet = true;
    } while (0);

    return bRet;
}
예제 #3
0
파일: P030.cpp 프로젝트: 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;
};
예제 #4
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
static KDbool splitWithForm ( const KDchar* szString, strArray& vStrings )
{
	KDbool  bRet = KD_FALSE;

    do 
    {
        CC_BREAK_IF ( !szString );

        // string is empty
        std::string   sContent = szString;
        CC_BREAK_IF ( sContent.length ( ) == 0 );

        KDuint  nPosLeft  = sContent.find ( '{' );
        KDuint  nPosRight = sContent.find ( '}' );

        // don't have '{' and '}'
        CC_BREAK_IF ( nPosLeft == std::string::npos || nPosRight == std::string::npos );
        // '}' is before '{'
        CC_BREAK_IF ( nPosLeft > nPosRight );

        std::string   sPointStr = sContent.substr ( nPosLeft + 1, nPosRight - nPosLeft - 1 );
        // nothing between '{' and '}'
        CC_BREAK_IF ( sPointStr.length ( ) == 0 );

        KDuint  nPos1 = sPointStr.find ( '{' );
        KDuint  nPos2 = sPointStr.find ( '}' );
        // contain '{' or '}' 
        CC_BREAK_IF ( nPos1 != std::string::npos || nPos2 != std::string::npos );

        split ( sPointStr, ",", vStrings );
        if ( vStrings.size ( ) != 2 || vStrings [ 0 ].length ( ) == 0 || vStrings [ 1 ].length ( ) == 0 )
        {
            vStrings.clear ( );
            break;
        }

        bRet = KD_TRUE;

    } while ( 0 );

    return bRet;
}
예제 #5
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
static bool splitWithForm(const std::string& content, strArray& strs)
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(content.empty());

        size_t nPosLeft  = content.find('{');
        size_t nPosRight = content.find('}');

        // don't have '{' and '}'
        CC_BREAK_IF(nPosLeft == std::string::npos || nPosRight == std::string::npos);
        // '}' is before '{'
        CC_BREAK_IF(nPosLeft > nPosRight);

        const std::string pointStr = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1);
        // nothing between '{' and '}'
        CC_BREAK_IF(pointStr.length() == 0);

        size_t nPos1 = pointStr.find('{');
        size_t nPos2 = pointStr.find('}');
        // contain '{' or '}' 
        CC_BREAK_IF(nPos1 != std::string::npos || nPos2 != std::string::npos);

        split(pointStr, ",", strs);
        if (strs.size() != 2 || strs[0].length() == 0 || strs[1].length() == 0)
        {
            strs.clear();
            break;
        }

        bRet = true;
    } while (0);

    return bRet;
}