• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 183,  comments - 10,  trackbacks - 0
             
             1 def my_range(start, stop = None, step = 1):
             2     # 實(shí)現(xiàn)自己的 range
             3     if stop == None:
             4         start, stop = 0, start
             5 
             6     result = []
             7     if step > 0:
             8         i = start
             9         while i < stop:
            10             result.append(i)
            11             i += step
            12     else:
            13         i = start
            14         while (i > stop):
            15             result.append(i)
            16             i += step
            17     return result
            18 
            19 print(my_range(10))
            20 print(my_range(5202))
            21 print(my_range(110))
            22 print(my_range(10, 0, -1))
            23 print(my_range(100, 0, -9))

            輸出:
            >>>
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
            [5, 7, 9, 11, 13, 15, 17, 19]
            [1, 2, 3, 4, 5, 6, 7, 8, 9]
            [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
            [100, 91, 82, 73, 64, 55, 46, 37, 28, 19, 10, 1]
            posted @ 2013-05-16 21:00 unixfy 閱讀(391) | 評(píng)論 (0)編輯 收藏
             1 def init(data):
             2     data['first'= {}
             3     data['middle'= {}
             4     data['last'= {}
             5 
             6 def lookup(data, label, name):
             7     return data[label].get(name)
             8 
             9 def store(data, full_name):
            10     names = full_name.split()
            11     if len(names) == 2:
            12         names.insert(1'')
            13     labels = 'first''middle''last'
            14     for label, name in zip(labels, names):
            15         people = lookup(data, label, name)
            16         if people:
            17             people.append(full_name)
            18         else:
            19             data[label][name] = [full_name]
            20 
            21 my_names = {}
            22 init(my_names)
            23 store(my_names, 'Magnus Lie Hetland')
            24 print(my_names)
            25 print(lookup(my_names, 'middle''Lie'))
            26 
            27 store(my_names, 'Robin Hood')
            28 store(my_names, 'Robin Locksley')
            29 print(my_names)
            30 print(lookup(my_names, 'first''Robin'))
            31 store(my_names, 'Mr. Gumby')
            32 print(my_names)
            33 print(lookup(my_names, 'middle'''))
            34 

            輸出:
            >>>
            {'middle': {'Lie': ['Magnus Lie Hetland']}, 'first': {'Magnus': ['Magnus Lie Hetland']}, 'last': {'Hetland': ['Magnus Lie Hetland']}}
            ['Magnus Lie Hetland']
            {'middle': {'': ['Robin Hood', 'Robin Locksley'], 'Lie': ['Magnus Lie Hetland']}, 'first': {'Robin': ['Robin Hood', 'Robin Locksley'], 'Magnus': ['Magnus Lie Hetland']}, 'last': {'Hetland': ['Magnus Lie Hetland'], 'Locksley': ['Robin Locksley'], 'Hood': ['Robin Hood']}}
            ['Robin Hood', 'Robin Locksley']
            {'middle': {'': ['Robin Hood', 'Robin Locksley', 'Mr. Gumby'], 'Lie': ['Magnus Lie Hetland']}, 'first': {'Mr.': ['Mr. Gumby'], 'Robin': ['Robin Hood', 'Robin Locksley'], 'Magnus': ['Magnus Lie Hetland']}, 'last': {'Hetland': ['Magnus Lie Hetland'], 'Locksley': ['Robin Locksley'], 'Gumby': ['Mr. Gumby'], 'Hood': ['Robin Hood']}}
            ['Robin Hood', 'Robin Locksley', 'Mr. Gumby']


            改進(jìn):利用收集參數(shù),一次可以添加多個(gè)名字 strage_2
             1 def init(data):
             2     data['first'= {}
             3     data['middle'= {}
             4     data['last'= {}
             5 
             6 def lookup(data, label, name):
             7     return data[label].get(name)
             8 
             9 def store(data, full_name):
            10     names = full_name.split()
            11     if len(names) == 2:
            12         names.insert(1'')
            13     labels = 'first''middle''last'
            14     for label, name in zip(labels, names):
            15         people = lookup(data, label, name)
            16         if people:
            17             people.append(full_name)
            18         else:
            19             data[label][name] = [full_name]
            20 
            21 def store_2(data, *full_names):
            22     for full_name in full_names:
            23         names = full_name.split()
            24         if len(names) == 2:
            25             names.insert(1'')
            26         labels = 'first''middle''last'
            27         for label, name in zip(labels, names):
            28             people = lookup(data, label, name)
            29             if people:
            30                 people.append(full_name)
            31             else:
            32                 data[label][name] = [full_name]
            33 
            34 my_names = {}
            35 init(my_names)
            36 store(my_names, 'Magnus Lie Hetland')
            37 print(my_names)
            38 print(lookup(my_names, 'middle''Lie'))
            39 
            40 store(my_names, 'Robin Hood')
            41 store(my_names, 'Robin Locksley')
            42 print(my_names)
            43 print(lookup(my_names, 'first''Robin'))
            44 store(my_names, 'Mr. Gumby')
            45 print(my_names)
            46 print(lookup(my_names, 'middle'''))

            posted @ 2013-05-16 20:12 unixfy 閱讀(235) | 評(píng)論 (0)編輯 收藏
            1 def foo():
            2     x = 5
            3     for i in range(3):
            4         print(i)
            5 for i in range(1013):
            6     print(i)
            7 
            8 foo()

            輸出:
            >>>
            10
            11
            12
            0
            1
            2


            1 def foo():
            2     x = 5
            3     for i in range(3):
            4         print(i)
            5     for i in range(1013):
            6         print(i)
            7 
            8 foo()

            輸出:
            >>>
            0
            1
            2
            10
            11
            12





            posted @ 2013-05-16 19:54 unixfy 閱讀(169) | 評(píng)論 (0)編輯 收藏
            類似于C++中的引用計(jì)數(shù)
             1 >>> x = 5
             2 >>> y = x
             3 >>> x == y
             4 True
             5 >>> x is y
             6 True
             7 >>> y = 3
             8 >>> x == y
             9 False
            10 >>> x is y
            11 False

             1 >>> x = 5
             2 >>> y = x
             3 >>> x == y
             4 True
             5 >>> x is y
             6 True
             7 >>> y = 5
             8 >>> x == y
             9 True
            10 >>> x is y
            11 True
            12 >>> y = 3
            13 >>> x == y
            14 False
            15 >>> x is y
            16 False


            posted @ 2013-05-16 19:21 unixfy 閱讀(91) | 評(píng)論 (0)編輯 收藏
             1 from math import sqrt
             2 
             3 def is_prim(n):
             4     if n < 2:
             5         return False
             6     for i in range(2, int(sqrt(n)) + 1):
             7         if n % i == 0:
             8             return False
             9     return True
            10 
            11 def get_prim(n):
            12     if n < 1:
            13         return None
            14     x = 1
            15     r = 3
            16     ret = 2
            17     while x < n:
            18         if is_prim(r) == True:
            19             x = x + 1
            20             ret = r
            21         r = r + 1
            22     return ret
            23 
            24 = int(input("Input n: "))
            25 print(get_prim(n))
            26 
            posted @ 2013-05-14 22:25 unixfy 閱讀(897) | 評(píng)論 (0)編輯 收藏
             1 people = {
             2     'Alice' : {
             3         'phone' : '2341',
             4         'addr'  : 'Foo drive 23'
             5         },
             6     'Beth' : {
             7         'phone' : '9102',
             8         'addr'  : 'Bar street 42'
             9         },
            10     'Cecil' : {
            11         'phone' : '3158',
            12         'addr'  : 'Baz avenue 90'
            13         }
            14     }
            15 
            16 labels = {
            17     'phone' : 'phone number',
            18     'addr'  : 'address'
            19     }
            20 
            21 name = input("Name:")
            22 
            23 request = input("phone number(p) or address(a)?")
            24 
            25 if request == 'p' : key = 'phone'
            26 if request == 'a' : key = 'addr'
            27 
            28 if name in people :
            29     print("%s's %s is %s." % (name, labels[key], people[name][key]))
            30 

            get 函數(shù),提供默認(rèn)值
             1 people = {
             2     'Alice' : {
             3         'phone' : '2341',
             4         'addr'  : 'Foo drive 23'
             5         },
             6     'Beth' : {
             7         'phone' : '9102',
             8         'addr'  : 'Bar street 42'
             9         },
            10     'Cecil' : {
            11         'phone' : '3158',
            12         'addr'  : 'Baz avenue 90'
            13         }
            14     }
            15 
            16 labels = {
            17     'phone' : 'phone number',
            18     'addr'  : 'address'
            19     }
            20 
            21 name = input("Name:")
            22 
            23 request = input("phone number(p) or address(a)?")
            24 
            25 key = request
            26 if request == 'p' : key = 'phone'
            27 if request == 'a' : key = 'addr'
            28 
            29 person = people.get(name, {})
            30 label  = labels.get(key, key)
            31 result = person.get(key, 'not available')
            32 
            33 print("%s's %s is %s." % (name, label, result))
            34 


            posted @ 2013-05-12 22:50 unixfy 閱讀(149) | 評(píng)論 (0)編輯 收藏
            Box
             1 sentence = input("Sentence: ")
             2 
             3 screen_width = 80
             4 text_width   = len(sentence)
             5 box_width    = text_width + 6
             6 left_margin  = int((screen_width - box_width) / 2)
             7 
             8 print()
             9 print(' ' * left_margin + '+' + '-' * (box_width-4+ '+')
            10 print(' ' * left_margin + '' + ' ' * text_width + ' |')
            11 print(' ' * left_margin + '' + sentence + ' |')
            12 print(' ' * left_margin + '' + ' ' * text_width + ' |')
            13 print(' ' * left_margin + '+' + '-' * (box_width-4+ '+')
            14 print()
            15 
            posted @ 2013-05-12 15:28 unixfy 閱讀(127) | 評(píng)論 (0)編輯 收藏
            《Python 基礎(chǔ)教程》
             1 months = [
             2     'January',
             3     'February',
             4     'March',
             5     'April',
             6     'May',
             7     'June',
             8     'July',
             9     'August',
            10     'September',
            11     'October',
            12     'November',
            13     'December'
            14     ]
            15 
            16 # print(month)
            17 
            18 endings = ['st''nd''rd'+ 17 * ['th'] \
            19         + ['st''nd''rd'+ 7  * ['th'] \
            20         + ['st']
            21 
            22 year  = input("Year: ")
            23 month = input("Month: ")
            24 day   = input("Day: ")
            25 
            26 month_number = int(month)
            27 day_number   = int(day)
            28 
            29 month_name   = months[month_number-1]
            30 ordinal      = day + endings[day_number-1]
            31 
            32 # print(1, 2, 3)
            33 print(month_name + ' ' + ordinal + '' + year)
            34 

            posted @ 2013-05-12 14:05 unixfy 閱讀(178) | 評(píng)論 (0)編輯 收藏
             

            互聯(lián)網(wǎng)上的商業(yè)模式

             

            商業(yè)模式經(jīng)濟(jì)上、商業(yè)上的定義我不知道。我所理解的商業(yè)模式就是“賺錢(qián)的模式”。

            “男怕入錯(cuò)行,女怕嫁錯(cuò)郎”,對(duì)于學(xué)計(jì)算機(jī)的人,想從事IT這個(gè)行業(yè)的人,以及正在這個(gè)行業(yè)工作的人都需要思考這個(gè)問(wèn)題:互聯(lián)網(wǎng)這個(gè)行業(yè)怎么樣,它可以使這個(gè)行業(yè)的人能夠?qū)崿F(xiàn)自己的價(jià)值嗎?

             

            史玉柱說(shuō)過(guò)網(wǎng)絡(luò)游戲是目前中國(guó)互聯(lián)網(wǎng)上最好的商業(yè)模式,這是他好多年前說(shuō)的,但是到目前為止,這句話依然有效,目前中國(guó)互聯(lián)網(wǎng)行業(yè)依然是互聯(lián)網(wǎng)上最好的商業(yè)模式,目前雖然電子商務(wù)發(fā)展的很好,但是它是燒錢(qián)的而不是賺錢(qián),這種燒錢(qián)模式不知道會(huì)持續(xù)多久。

            目前中國(guó)幾大互聯(lián)網(wǎng)公司,雖然其主營(yíng)業(yè)務(wù)看起來(lái)不是網(wǎng)絡(luò)游戲,但是實(shí)質(zhì)上都是以網(wǎng)絡(luò)游戲生存著的。騰訊是中國(guó)互聯(lián)網(wǎng)上收入最多的公司,其游戲收入比重占了一半以上,網(wǎng)易有一半以上的收入也是來(lái)自網(wǎng)絡(luò)游戲,搜狐暢游、盛大、金山、人人等。

             

            百度不是靠游戲?yàn)樯?,?jìng)價(jià)排名是一直被人所詬病的,排除廣告的因素,競(jìng)價(jià)排名確實(shí)是一種很好的賺錢(qián)模式,使得百度收入逐年增高。

             

            360 是一家很好的公司,其倡導(dǎo)免費(fèi)模式,在推出了安全瀏覽器和網(wǎng)址導(dǎo)航后開(kāi)始了一些盈利。

            現(xiàn)在很多人的觀點(diǎn)是一定要先免費(fèi),增加用戶量,用戶上去了自然而然就會(huì)有賺錢(qián)模式。我并不認(rèn)同這種觀點(diǎn),因?yàn)椴⒉皇敲總€(gè)人都是周鴻祎,在你用戶還沒(méi)上去之前你的公司可能早已經(jīng)死了,所以別人可以做的事,并不代表你可以做。別人可以先做用戶量,別人可以拿到天使投資、風(fēng)險(xiǎn)投資,而你并不一定拿到。

            最保險(xiǎn)的方法就是在你的公司初創(chuàng)時(shí)期就考慮怎么賺錢(qián),怎么能生成下去。

             

            視頻網(wǎng)站也是中國(guó)互聯(lián)網(wǎng)上一個(gè)比較打的模式,視頻網(wǎng)站也是很燒錢(qián),現(xiàn)在優(yōu)酷做起來(lái)了,開(kāi)始有了自己的廣告、收費(fèi)視頻節(jié)目、自制的一些節(jié)目(曉說(shuō)、潘石屹、財(cái)經(jīng)類等),但是中國(guó)互聯(lián)網(wǎng)上也盡只有優(yōu)酷、愛(ài)奇藝、搜狐視頻等幾家公司。

             

            電子商務(wù)被很多人看好,已經(jīng)迅猛發(fā)展很多年了。前幾天的雙11淘寶-天貓銷售額達(dá)到191億,這個(gè)數(shù)字是龐大的。

            目前國(guó)內(nèi)電子商務(wù)模式主要有三種:阿里的平臺(tái)式;京東、亞馬遜、一號(hào)店、當(dāng)當(dāng)?shù)冗@種沃爾瑪、國(guó)美式;還有一種是自做品牌的如凡客、樂(lè)淘等。在我看來(lái),這三種模式更看好平臺(tái)式的,電子商務(wù)的精髓在于電子,而非商務(wù),因?yàn)樯虅?wù)早就存在,所以沒(méi)有必要再創(chuàng)造出一個(gè)新的電子的品牌。能夠體現(xiàn)電子的,就是讓線下的東西能夠通過(guò)電子的方式銷售,而淘寶-天貓就是做的這個(gè)。

             

            計(jì)算機(jī)發(fā)展到現(xiàn)在,在我看來(lái)主要是三個(gè)部分:硬件、軟件、互聯(lián)網(wǎng)。比爾蓋茨的軟件模式是一個(gè)非常好的模式,一直到現(xiàn)在為止依然是微軟、甲骨文這些公司。

             

            關(guān)于風(fēng)險(xiǎn)投資,我想風(fēng)險(xiǎn)投資是隨著計(jì)算機(jī)互聯(lián)網(wǎng)發(fā)展起來(lái)的,如果一家創(chuàng)始人從創(chuàng)辦開(kāi)始就可以自負(fù)盈虧、贏利,那么它為什么要為了一點(diǎn)資金而稀釋自己的股份,風(fēng)投之所以伴隨著互聯(lián)網(wǎng)的發(fā)展是因?yàn)榛ヂ?lián)網(wǎng)公司一開(kāi)始就沒(méi)有造血的功能,需要不斷的供血,不斷的供血,知道能夠上市或者被收購(gòu),這樣給風(fēng)投者以巨大的回報(bào)。

            我個(gè)人并不看好這種模式,因?yàn)槟軌蚶斤L(fēng)投不是一般人能為之的,另外,即便拉到風(fēng)投成功的也很少,這不是一條理性的道路。

             

            我理想的創(chuàng)業(yè)模式是那種傳統(tǒng)軟件的模式,一開(kāi)始就可以自負(fù)盈虧,自己靠自己生存,和風(fēng)投沒(méi)有關(guān)系,按照自己的步調(diào)走。

            /Files/unixfy/互聯(lián)網(wǎng)上的商業(yè)模式_mark.doc

            posted @ 2012-11-22 10:33 unixfy 閱讀(155) | 評(píng)論 (0)編輯 收藏

            統(tǒng)一的考勤處理程序

            總共分為 6 個(gè)處理步驟,如下:
            0. 進(jìn)行考勤數(shù)據(jù)的預(yù)處理,其中有篩選打卡成功的記錄,并對(duì)成功的記錄進(jìn)行排序。這一步比較靈活,根據(jù)不同的考勤數(shù)據(jù)做不同的預(yù)處理以得到后續(xù)可以處理的數(shù)據(jù)。
            1. 針對(duì)打卡成功的考勤記錄,找出每天的最早時(shí)間和最晚時(shí)間。
            2. 根據(jù)最早時(shí)間和最晚時(shí)間得到遲到和早退記錄。
            3. 由于可能存在缺勤的情況,所以需要在制定工作日內(nèi)找到未存在考勤記錄的記錄,作為缺勤記錄。
            4. 將前面的遲到和早退記錄與缺勤記錄進(jìn)行整合。
            5. 根據(jù)整合的結(jié)果輸出考勤異常的記錄。輸出有多種形式,前面的遲到、早退、缺勤等數(shù)據(jù)一定了,這里的輸出格式可以按照:按人名-行輸出、按人名-列輸出、按日期-行輸出、按日期-列輸出、人名-日期輸出、日期-人名輸出等多種方式。

            具體的程序?qū)崿F(xiàn)如下:
            0.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <string>
            #include <vector>
            #include <algorithm>
            using namespace std;

            int main()
            {
             ifstream fin_kaoqin("kaoqin.txt");
             ofstream fout_0("0.txt");
             if (!fin_kaoqin || !fout_0)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             vector<string> checkins;
             string name, date, time;
             string s1, s2, s3, ind;
             string line;
             while (getline(fin_kaoqin, line))
             {
              istringstream sin(line);
              sin >> s1 >> s2 >> name >> date >> time >> s3 >> ind;
              if (ind != "成功")
              {
               continue;
              }
              checkins.push_back(name + '\t' + date + '\t' + time);
             }
             sort(checkins.begin(), checkins.end());
             for (vector<string>::size_type i = 0; i != checkins.size(); ++i)
             {
              fout_0 << checkins[i] << endl;
             }
             fin_kaoqin.close();
             fout_0.close();
             return 0;
            }

            1.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <map>
            #include <set>
            #include <vector>
            #include <string>
            using namespace std;

            int main()
            {
             ifstream fin("0.txt");
             ofstream fout("1.txt");
             ofstream fout_names("names.txt");
             ofstream fout_dates("dates.txt");
             if (!fin || !fout || !fout_names || !fout_dates)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             map<string, vector<string> > checkins;
             set<string> names, dates;
             string line;
             string name, date, time;
             while (getline(fin, line))
             {
              istringstream sin(line);
              sin >> name >> date >> time;
              names.insert(name);
              dates.insert(date);
              checkins[name + '\t' + date].push_back(time);
             }
             string earliest, lastest;
             for (map<string, vector<string> >::const_iterator cit = checkins.begin(); cit != checkins.end(); ++cit)
             {
              earliest = lastest = cit->second[0];
              for (vector<string>::size_type i = 0; i != cit->second.size(); ++i)
              {
               if (earliest > cit->second[i])
               {
                earliest = cit->second[i];
               }
               else if (lastest < cit->second[i])
               {
                lastest = cit->second[i];
               }
              }
              fout << cit->first << '\t' << earliest << endl;
              fout << cit->first << '\t' << lastest  << endl;
             }
             for (set<string>::const_iterator cit = names.begin(); cit != names.end(); ++cit)
             {
              fout_names << *cit << endl;
             }
             for (set<string>::const_iterator cit = dates.begin(); cit != dates.end(); ++cit)
             {
              fout_dates << *cit << endl;
             }
             fin.close();
             fout.close();
             fout_names.close();
             fout_dates.close();
             return 0;
            }

            2.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <string>
            using namespace std;

            struct checkin
            {
             string name;
             string date;
             string time;
            };

            void foo(ofstream& fout_nor, ofstream& fout_abn, const checkin& ci1, const checkin& ci2, const string& start, const string& end)
            {
             if (ci1.time <= start)
             {
              fout_nor << ci1.name << '\t' << ci1.date << '\t' << ci1.time << endl;
             }
             else
             {
              fout_abn << ci1.name << '\t' << ci1.date << '\t' << ci1.time << "遲到" << endl;
             }
             if (ci2.time >= end)
             {
              fout_nor << ci2.name << '\t' << ci2.date << '\t' << ci2.time << endl;
             }
             else
             {
              fout_abn << ci2.name << '\t' << ci2.date << '\t' << ci2.time << "早退" << endl;
             }
            }

            int main()
            {
             ifstream fin("1.txt");
             ofstream fout_nor("2-normal.txt"), fout_abn("2-abnormal.txt");
             if (!fin || !fout_nor || !fout_abn)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             string line1, line2;
             checkin ci1, ci2;
             string start = "083000", end = "173000";
             while (getline(fin, line1) && getline(fin, line2))
             {
              istringstream sin1(line1), sin2(line2);
              sin1 >> ci1.name >> ci1.date >> ci1.time;
              sin2 >> ci2.name >> ci2.date >> ci2.time;
              foo(fout_nor, fout_abn, ci1, ci2, start, end);
             }
             fin.close();
             fout_nor.close();
             fout_abn.close();
             return 0;
            }

            3.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <string>
            #include <map>
            #include <set>
            #include <vector>
            using namespace std;

            int main()
            {
             ifstream fin_ci("0.txt");
             ifstream fin_name("names-filter.txt");
             ifstream fin_date("dates-filter.txt");
             ofstream fout_nowork("2.1-nowork.txt");
             if (!fin_ci || !fin_name || !fin_date || !fout_nowork)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             map<string, set<string> > name_date;
             string line, name, date;
             while (getline(fin_ci, line))
             {
              istringstream sin(line);
              sin >> name >> date;
              name_date[name].insert(date);
             }
             vector<string> names;
             while (fin_name >> line)
             {
              names.push_back(line);
             }
             vector<string> dates;
             while (fin_date >> line)
             {
              dates.push_back(line);
             }
             for (vector<string>::size_type i = 0; i != names.size(); ++i)
             {
              for (vector<string>::size_type j = 0; j != dates.size(); ++j)
              {
               if (name_date[names[i]].find(dates[j]) == name_date[names[i]].end())
               {
                fout_nowork << names[i] << '\t' << dates[j] << '\t' << "無(wú)出勤記錄!" << endl;
               }
              }
             }
             fin_ci.close();
             fin_name.close();
             fin_date.close();
             fout_nowork.close();
             return 0;
            }

            4.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <string>
            #include <vector>
            #include <algorithm>
            using namespace std;

            int main()
            {
             ifstream fin_abnormal("2-abnormal.txt");
             ifstream fin_nowork("2.1-nowork.txt");
             ofstream fout_excep("2.2-exception.txt");
             if (!fin_abnormal || !fin_nowork || !fout_excep)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             vector<string> checkins;
             string line;
             while (getline(fin_abnormal, line))
             {
              checkins.push_back(line);
             }
             while (getline(fin_nowork, line))
             {
              checkins.push_back(line);
             }
             sort(checkins.begin(), checkins.end());
             for (vector<string>::size_type i = 0; i != checkins.size(); ++i)
             {
              fout_excep << checkins[i] << endl;
             }
             fin_abnormal.close();
             fin_nowork.close();
             fout_excep.close();
             return 0;
            }

            5.
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <string>
            #include <map>
            #include <set>
            #include <vector>
            using namespace std;

            struct date_time
            {
             string date;
             string time;
            };

            int main()
            {
             ifstream fin_ci("2.2-exception.txt");
             ifstream fin_names("names-filter.txt");
             ifstream fin_dates("dates-filter.txt");
             ofstream fout_row("3-name-row-filter.txt");
             ofstream fout_col("3-name-column-filter.txt");
             if (!fin_ci || !fout_row || !fout_col || !fin_names || !fin_dates)
             {
              cerr << "File error!" << endl;
              system("PAUSE");
              exit(1);
             }
             map<string, vector<date_time> > bypers;
             vector<string> names;
             string line, name;
             date_time dt;
             int MAXNUM = 0;
             // 讀取想要的人名
             set<string> names_filter;
             while (fin_names >> name)
             {
              names_filter.insert(name);
             }
             // 讀取想要的日期
             set<string> dates_filter;
             while (fin_dates >> line)
             {
              dates_filter.insert(line);
             }
             while (getline(fin_ci, line))
             {
              istringstream sin(line);
              sin >> name >> dt.date >> dt.time;
              // 提取想要的人名和日期
              if (names_filter.find(name) == names_filter.end() || dates_filter.find(dt.date) == dates_filter.end())
              {
               continue;
              }
              bypers[name].push_back(dt);
             }
             // 同名字下相同日期的合并
             for (map<string, vector<date_time> >::iterator cit = bypers.begin(); cit != bypers.end(); ++cit)
             {
              // 提取名字
              names.push_back(cit->first);
              
              vector<date_time> tmp, hold = cit->second;
              vector<date_time>::size_type i = 0;
              while (i < hold.size() - 1)
              {
               if (hold[i].date == hold[i+1].date)
               {
                dt.date = hold[i].date;
                dt.time = hold[i].time + hold[i + 1].time;
                tmp.push_back(dt);
                i += 2;
               }
               else
               {
                dt.date = hold[i].date;
                dt.time = hold[i].time;
                tmp.push_back(dt);
                ++i;
               }
              }
              // 最后兩個(gè)如果相等,那么 i 一下子回跳到 hold.size()。
              // 如果不相等,那么 i 變成 hold.size() - 1, 推出循環(huán)。
              // 也就是說(shuō)推出循環(huán)有兩種情況,分別是 i 為 hold.size() 和 hold.size() - 1
              // i 為 hold.size() 的情況沒(méi)有遺漏記錄,i 為 hold.size() - 1 遺漏了數(shù)據(jù),所以在此補(bǔ)充。
              if (i == hold.size() - 1)
              {
               dt.date = hold[i].date;
               dt.time = hold[i].time;
               tmp.push_back(dt);
               ++i;
              }
              // 記錄最大記錄個(gè)數(shù)
              if (MAXNUM < tmp.size())
              {
               MAXNUM = tmp.size();
              }
              cit->second = tmp;
             }
             // 按行輸出
             for (map<string, vector<date_time> >::const_iterator cit = bypers.begin(); cit != bypers.end(); ++cit)
             {
              fout_row << cit->first << '\t';
              for (vector<date_time>::size_type i = 0; i != cit->second.size(); ++i)
              {
               fout_row << cit->second[i].date << '\t' << cit->second[i].time << '\t';
              }
              fout_row << endl;
             }
             
             // 先輸出人名
             for (vector<string>::size_type i = 0; i != names.size(); ++i)
             {
              fout_col << names[i] << '\t';
             }
             fout_col << endl;
             // 按列輸出
             for (int i = 0; i != MAXNUM; ++i)
             {
              for (vector<string>::size_type j = 0; j != names.size(); ++j)
              {
               if (bypers[names[j]].size() > i)
               {
                fout_col << bypers[names[j]][i].date << ',' << bypers[names[j]][i].time << '\t';
               }
               else
               {
                fout_col /* << "XXXXXX" */ << '\t';
                // 這里的輸出 "XXXXXX" 可以省略,即可以直接 fout_col << '\t';
               }
              }
              fout_col << endl;
             }
             fin_ci.close();
             fout_row.close();
             fout_col.close();
             return 0;
            }

            posted @ 2012-10-29 17:04 unixfy 閱讀(166) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題
            共19頁(yè): 1 2 3 4 5 6 7 8 9 Last 
            久久综合九色综合网站| 久久亚洲私人国产精品| 看全色黄大色大片免费久久久| 精品免费久久久久国产一区| 久久精品中文字幕有码| 国内精品九九久久精品| 久久久久久狠狠丁香| 亚洲国产成人久久综合野外| 一本一本久久a久久综合精品蜜桃| 日韩av无码久久精品免费| 久久国产精品偷99| 久久夜色精品国产网站| 久久久久无码精品国产app| 亚洲va久久久噜噜噜久久天堂| 国产欧美久久久精品| 99蜜桃臀久久久欧美精品网站| 天天久久狠狠色综合| 久久国产免费直播| 久久99精品九九九久久婷婷| 无码国产69精品久久久久网站| 国产精品成人99久久久久91gav| 久久强奷乱码老熟女网站| 久久久精品日本一区二区三区| 久久精品无码专区免费东京热 | 亚洲va久久久久| 婷婷综合久久狠狠色99h| 久久九九久精品国产免费直播| 久久WWW免费人成—看片| 69久久精品无码一区二区| 亚洲国产欧美国产综合久久 | 久久综合亚洲欧美成人| 色狠狠久久综合网| 亚洲人成网站999久久久综合| 国产福利电影一区二区三区,免费久久久久久久精 | 亚洲国产天堂久久综合网站| 麻豆亚洲AV永久无码精品久久| 国产99久久久国产精品小说| 久久毛片一区二区| 狠狠色狠狠色综合久久| 久久精品国产亚洲AV影院| 麻豆AV一区二区三区久久|