首页 > ACM题库 > HDU-杭电 > hdu 3447 Count The Keyword待解决[解题报告]C++
2014
03-23

hdu 3447 Count The Keyword待解决[解题报告]C++

Count The Keyword

问题描述 :

John loves various languages. Recently he begins to learn C programming language. He is interested in the keyword of C and knows the importance of keywords. So each time he gets a C program source code, he counts the the appearance of the valid keyword first. However, when the code is long, John can’t count it correctly. Now he needs your help, he will give you some C code, and he wants you tell him the correct number of the appearance of the keyword.
In order to make the problem easier. John provides you some information.
1, the code don’t contain "#define", i.e. the code don’t contain the Macro definition .
2, the code may contain type cast, i.e. int a = (int)b;
3, the keywords in the comments are not valid.
4, the keywords in a string are not valid, and the character in the string will be expressed by letter. i.e. The string like "ab\x40" will not appear.
5, it guarantees that a word or a statement is in the same line, but one line may contain many words or statements.
6, one line contain no more than 300 characters and one word is less than 50 characters.

输入:

The input file contains no more than 10 cases.
Each case contains a completely or incompletely correct C program and cases are separated by a line contains only four ‘#’, i.e. "####".

输出:

The input file contains no more than 10 cases.
Each case contains a completely or incompletely correct C program and cases are separated by a line contains only four ‘#’, i.e. "####".

样例输入:

#include <stdio.h>
main(){
int a;
int b;
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}

样例输出:

2

Hint
Below is the 32 keywords in C language. auto break case char const continue default do double else enum extern float for goto if int long register return short signed static sizeof struct switch typedef union unsigned void volatile while


  1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

  2. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  3. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术,也不懂什么是算法,从而也不要求程序员懂什么算法,做程序从来不考虑性能问题,只要页面能显示出来就是好程序,这是国内的现状,很无奈。