A netizen is working on the school to do a curriculum design, requiring the location of the given word to appear in a file and statistics. This is a relatively simple text handling problem, so I wrote one with Python and bet in 5 minutes to solve the problem in 5 minutes. I made it, the following is the program:
IF __name __ == '__ main__': file_name = Raw_Input ('Input the file you want to find in:') TRY: IN_FILE = Open (file_name, 'r') lines = in_file.readlines ()
Tag_tok = '' while tag_tok.upper ()! = 'q': tag_tok = Raw_INPUT (q for quit: ') if tag_tok.upper ()! =' q ': count = 0 line_no = 0 for line in line: line_no = line_no 1 inline_cnt = line.count (tag_tok) count = count inline_cnt if inline_cnt> 0: Print 'Find% S% D Time (s) in line:% d'% (tag_tok, inline_cnt, line_no) Print Line Print '--------------------------------' Print 'Total FOUNT% S% D Time (S) '% (tag_tok, count) Except: print "can't open file% s"% (file_name)
However, this netizen does not satisfy the procedure for a C , the reason is that their teachers will not python, just try to try to solve the comparison with Python with C :
#include
Using namespace std;
INT Brutefind (const char * x, int m, constor * y, int N, vector
Return Find_cnt;}
INT main () {string file_name, line; vector
INT line_count = 0; do {getLine (IN_FILE, LINES [LINE_COUNT]); line_count ; if (line_count == lines.size ()) {lines.resize (line_count * 2);}} while (in_file.eof == 0); string tag_tok; vector From the program length and programming time, rough comparison: Python 5 minutes 22 lines C 30 minutes more than 60 lines From this simple example, you can see the difference between the scripting language and the C language.