Esempio n. 1
0
File: 123.cpp Progetto: harshvs/cp3
int main(int argc, char *argv[])
{
    int cases;
    scanf("%d", &cases);
    while(cases--)
    {
        char input[16];
        scanf("%s", &input);
        int num = isPartialMatch(input, "one") ? 1 : (isPartialMatch(input, "two") ? 2 : 3);
        printf("%d\n", num);
    }
    
    return 0;
}
Esempio n. 2
0
/**
 * Parse a possible sequence extract it into prefix, suffix, and parameters.
 */
int ControlSeqParser::parseSeq()
{
	bool bDone = false;
	char prefix[4] = { 0, 0, 0, 0 };
	char suffix = 0;
	int nResult;
	int nPrefixIndex = 0;

	reset();

	while(!bDone)
	{
		switch(m_currentPos)
		{
		case 0:
			if (m_currentChar == ESC_CHAR)
			{
				nextChar();
			}
			else
			{
				bDone = true;
			}
			break;
		default:
			if (m_currentChar == '\0')
			{
				//End of string.
				bDone = true;
				break;
			}

			//First test if the current state matches any control sequence in full.
			if ((nResult = match(prefix, m_currentChar, m_values, m_numValues)) != CS_UNKNOWN)
			{
				nextChar();
				return nResult;
			}

			prefix[nPrefixIndex++] = m_currentChar;

			//Check if the prefix might lead to a valid sequence.
			if (!isPartialMatch(prefix))
			{
				//Match not found, maybe number parameters are located here instead.
				prefix[--nPrefixIndex] = 0;
				m_numValues = parsePositiveInt(m_values, MAX_NUM_VALUES);

				if (!isPartialMatch(prefix, m_values, m_numValues))
				{
					//Unknown sequence.
					bDone = true;
				}
				else
				{
					//Must end after read parameters.
					nResult = match(prefix, m_currentChar, m_values, m_numValues);
					nextChar();

					return nResult;
				}
			}
			else
			{
				nextChar();
			}
			break;
		}
	}

	return CS_UNKNOWN;
}