Problem1903--【高级语言程序设计】10.12 关键字统计V2

1903: 【高级语言程序设计】10.12 关键字统计V2

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

请编写一个程序,完成对输入的以空格为分隔的多个标识符中 C 关键词的统计。先输入多个标识符,每个标识符以空格为分隔符,所有标识符输入完毕后以回车符结束,然后输出其中出现的 C 关键字的统计结果,即每个关键字出现的次数。

Input

输入多个标识符,每个标识符以空格为分隔符,所有标识符输入完毕后以回车符结束。

Output

输出其中出现的 C 关键字的统计结果,即每个关键字出现的次数。

Sample Input Copy

for while for int float

Sample Output Copy

Results:
float:1
for:2
int:1
while:1

HINT

算法思想

利用循环输入多个单词和输出关键字统计结果,if-else if判断语句切分单词并保存到二维字符数组。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define N 32   //关键字数量
#define M 50   //输入的句子中的字符数
#define LEN 10 //每个单词的最大长度
int InputWord(char s[][LEN]);
void OutputCountResults(char *keywords[] , int count[], int n);
int IsKeyword(char s[]);
void CountKeywords(char s[][LEN], int n);
int main(void)
{
    //=======begin=======




    //========end========
}
//函数功能:以空格符作为分隔符输入包含多个单词的字符序列,切分单词并保存到二维字符数组
int InputWord(char word[][LEN])
{
    //=======begin=======






    //========end========
}
//函数功能:输出关键字统计结果
void OutputCountResults(char *keywords[], int count[], int n)
{
    //=======begin=======





    //========end========
}
//函数功能:判断s是否是C语言关键字,若是,则返回其下标,否则返回-1
int IsKeyword(char s[])
{
    char *keywords[N] = {"auto", "break", "case", "char", "const",
                           "continue", "default", "do", "double","else",
                           "enum", "extern", "float", "for", "goto",
                           "if", "int", "long", "register", "return",
                           "short", "singed", "sizeof", "static",
                           "struct", "switch", "typedef", "union",
                           "unsigned", "void", "volatile", "while"
}; //字符指针数组构造关键字词典
    //=======begin=======



    //========end========
}
//函数功能:统计二维字符数组s中关键字的数量存于结构体数组keywords的count成员中
void CountKeywords(char s[][LEN], int n)
{    
    char *keywords[N] = {"auto", "break", "case", "char", "const",
                           "continue", "default", "do", "double","else",
                           "enum", "extern", "float", "for", "goto",
                           "if", "int", "long", "register", "return",
                           "short", "singed", "sizeof", "static",
                           "struct", "switch", "typedef", "union",
                           "unsigned", "void", "volatile", "while"
}; //字符指针数组构造关键字词典
    //=======begin=======





    //========end========
}

Source/Category