<commit_before>//==================================================================
// ָOfferԹپͱ⡷
// ߣκ
//==================================================================

// 20ʾֵַ
// ĿʵһжַǷʾֵС磬
// ַ+1005e2-1233.1416-1E-16ʾֵ12e
// 1a3.141.2.3+-512e+5.4

#include <stdio.h>

bool scanUnsignedInteger(const char** str);
bool scanInteger(const char** str);

// ֵĸʽA[.[B]][e|EC].B[e|EC]ʾAC
// ţҲûУBһ޷
bool isNumeric(const char* str)
{
    if(str == nullptr)
        return false;

    bool numeric = scanInteger(&str);

    // '.'ֵС
    if(*str == '.')
    {
        ++str;

        // һд||ԭ
        // 1. Сû֣.1230.123
        // 2. Сû֣233.233.0
        // 3. ȻСǰͺ֣233.666
        numeric = scanUnsignedInteger(&str) || numeric;
    }

    // 'e''E'ŵֵָ
    if(*str == 'e' || *str == 'E')
    {
        ++str;

        // һд&&ԭ
        // 1. eEǰûʱַܱʾ֣.e1e1
        // 2. eEûʱַܱʾ֣12e12e+5.4
        numeric = numeric && scanInteger(&str);
    }

    return numeric && *str == '\0';
}

bool scanUnsignedInteger(const char** str)
{
    const char* before = *str;
    while(**str != '\0' && **str >= '0' && **str <= '9')
        ++(*str);

    // strд0-9ʱtrue
    return *str > before;
}

// ĸʽ[+|-]Bʾ, BΪ޷
bool scanInteger(const char** str)
{
    if(**str == '+' || **str == '-')
        ++(*str);
    return scanUnsignedInteger(str);
}

// ====================Դ====================
void Test(const char* testName, const char* str, bool expected)
{
    if(testName != nullptr)
        printf("%s begins: ", testName);

    if(isNumeric(str) == expected)
        printf("Passed.\n");
    else
        printf("FAILED.\n");
}


int main(int argc, char* argv[])
{
    Test("Test1", "100", true);
    Test("Test2", "123.45e+6", true);
    Test("Test3", "+500", true);
    Test("Test4", "5e2", true);
    Test("Test5", "3.1416", true);
    Test("Test6", "600.", true);
    Test("Test7", "-.123", true);
    Test("Test8", "-1E-16", true);
    Test("Test9", "1.79769313486232E+308", true);

    printf("\n\n");

    Test("Test10", "12e", false);
    Test("Test11", "1a3.14", false);
    Test("Test12", "1+23", false);
    Test("Test13", "1.2.3", false);
    Test("Test14", "+-5", false);
    Test("Test15", "12e+5.4", false);
    Test("Test16", ".", false);
    Test("Test17", ".e1", false);
    Test("Test18", "e1", false);
    Test("Test19", "+.", false);

    return 0;
}<commit_msg>Add two test cases into question 20.<commit_after>//==================================================================
// ָOfferԹپͱ⡷
// ߣκ
//==================================================================

// 20ʾֵַ
// ĿʵһжַǷʾֵС磬
// ַ+1005e2-1233.1416-1E-16ʾֵ12e
// 1a3.141.2.3+-512e+5.4

#include <stdio.h>

bool scanUnsignedInteger(const char** str);
bool scanInteger(const char** str);

// ֵĸʽA[.[B]][e|EC].B[e|EC]ʾAC
// ţҲûУBһ޷
bool isNumeric(const char* str)
{
    if(str == nullptr)
        return false;

    bool numeric = scanInteger(&str);

    // '.'ֵС
    if(*str == '.')
    {
        ++str;

        // һд||ԭ
        // 1. Сû֣.1230.123
        // 2. Сû֣233.233.0
        // 3. ȻСǰͺ֣233.666
        numeric = scanUnsignedInteger(&str) || numeric;
    }

    // 'e''E'ŵֵָ
    if(*str == 'e' || *str == 'E')
    {
        ++str;

        // һд&&ԭ
        // 1. eEǰûʱַܱʾ֣.e1e1
        // 2. eEûʱַܱʾ֣12e12e+5.4
        numeric = numeric && scanInteger(&str);
    }

    return numeric && *str == '\0';
}

bool scanUnsignedInteger(const char** str)
{
    const char* before = *str;
    while(**str != '\0' && **str >= '0' && **str <= '9')
        ++(*str);

    // strд0-9ʱtrue
    return *str > before;
}

// ĸʽ[+|-]Bʾ, BΪ޷
bool scanInteger(const char** str)
{
    if(**str == '+' || **str == '-')
        ++(*str);
    return scanUnsignedInteger(str);
}

// ====================Դ====================
void Test(const char* testName, const char* str, bool expected)
{
    if(testName != nullptr)
        printf("%s begins: ", testName);

    if(isNumeric(str) == expected)
        printf("Passed.\n");
    else
        printf("FAILED.\n");
}


int main(int argc, char* argv[])
{
    Test("Test1", "100", true);
    Test("Test2", "123.45e+6", true);
    Test("Test3", "+500", true);
    Test("Test4", "5e2", true);
    Test("Test5", "3.1416", true);
    Test("Test6", "600.", true);
    Test("Test7", "-.123", true);
    Test("Test8", "-1E-16", true);
    Test("Test9", "1.79769313486232E+308", true);

    printf("\n\n");

    Test("Test10", "12e", false);
    Test("Test11", "1a3.14", false);
    Test("Test12", "1+23", false);
    Test("Test13", "1.2.3", false);
    Test("Test14", "+-5", false);
    Test("Test15", "12e+5.4", false);
    Test("Test16", ".", false);
    Test("Test17", ".e1", false);
    Test("Test18", "e1", false);
    Test("Test19", "+.", false);
    Test("Test20", "", false);
    Test("Test21", nullptr, false);

    return 0;
}
{'fraction_non_alphanumeric': 0.29644187008688455, 'fraction_numerical': 0.06992139015308234, 'mean_word_length': 2.62987987987988, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4721649', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1958, 'n_words': 359}