你會怎麼解決它?(By C)

Now, I have a txt file, I want to count how many times the integers (range form 1 to 30) have appear in it.......
How you would work it out by C?

https://www.sendspace.com/file/r5lnw2

回覆 1# 毒得太遲


    no ching help me

TOP

the requirement is that I should provide 4 totally different  methods to finish this task...

TOP

回覆 3# 毒得太遲


    I only know 1 method, use fscanf() to read the file and put all the data to the corresponding arrays....... for example     IF (i=11){a[10]++}      IF (i=12){a[11]++}

TOP

回覆  毒得太遲


    I only know 1 method, use fscanf() to read the file and put all the data to th ...
毒得太遲 發表於 2015-3-26 21:56



    so u can use a [  i] +=1;

TOP

本帖最後由 ip4368 於 2015-3-27 12:12 編輯
回覆  毒得太遲


    I only know 1 method, use fscanf() to read the file and put all the data to th ...
毒得太遲 發表於 2015-3-26 21:56


如果用python, 我就會放落array/list, 因為python可以用str.split()+list.count()就做完. 但如果用c我一路read一路count算啦.
編輯: C就無寫到, 我寫左python, 比個答案你對啦, 因為python基本上可以肯定正確. 你個file嘅答案
再編輯: 當我無講過, 我縮小個dataset之後test一次, 發覺有錯, 我搵緊bug...
再再編輯: python未寫好, 竟然寫完C, 試過大細data(我用text editor check ans), 應該正確:
1: 91056
2: 10024
3: 129483
4: 2130
5: 12948
6: 2923
7: 38009
8: 51793
9: 104422
10: 2379579
11: 208
12: 29655
13: 25061
14: 125
15: 45945
16: 710
17: 54299
18: 284029
19: 15036
20: 73513
21: 417
22: 50122
23: 2506
24: 3341
25: 137837
26: 142014
27: 250
28: 17125
29: 19130
30: 35503

TOP

the requirement is that I should provide 4 totally different  methods to finish this task...
毒得太遲 發表於 2015-3-26 21:54

無睇你原來要4個method,scan完直接count,唔好放落array,咪另一個方法。

TOP

本帖最後由 Charcoal99 於 2015-3-27 14:22 編輯

跟本唔知你所指的4種Method 是指那個層面的??
如果你是指要4種stdio 的file讀取方法的話, 它們可以是
fgetc(), fgets(), fscanf() 及 fread(), 逐byte, 逐行, 逐Entity, 逐段 讀取。
如果你指的是解讀手法的話, 它們可以用 fscanf(), split(), match(), regrex(),  equal() ......
你也可以每次只scan 1 個數, scan 30次, 也可以一次個讀入大array,
可以用integer 處理, 也可以是String 處理,  答案五花八門, 要多少有多少。

TOP

回覆 8# Charcoal99


    Different Big-O..

TOP

回覆  Charcoal99


    Different Big-O..
毒得太遲 發表於 2015-3-27 17:25

then u can make the first best version, then inflate the best version with junk loop, then ur big-o will inflate as well

TOP