统计词长度,C++求解答描述假定一篇文章由若干词组成,单词之间通过英语的逗号、句点或空格间隔.想统计不同长度的单词数量,

1个回答

  • #include

    using namespace std;

    int isa(char c)

    {

    return ('A' <= c&&c <= 'Z')||('a' <= c&&c <= 'z');

    }

    int main()

    {

    char w[10000];//设输入最长不超过10000个字符

    intc[51] = { 0 };//设最长的词不超过50个字母

    int curl = 0;

    int i, s = 0,t=0;

    cin.getline(w, 10000);

    for (i = 0; i

    {

    if (isa(w[i] ))

    {

    curl++;

    }

    else

    {

    c[curl]++;

    curl = 0;

    }

    }

    for (i = 1; i <= 50; i++)

    {

    if (c[i])

    {

    s += i*c[i];

    t += c[i];

    cout << '(' << i<}

    }

    cout << s < return 0;

    }i am a student

    (1,2)

    (2,1)

    (7,1)

    11/4

    请按任意键继续. . .