• <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>

            hdu - 1225:Football Score

               這是個(gè)簡(jiǎn)單的字符串處理題目。看題目,數(shù)據(jù)應(yīng)該不是很大,直接暴力處理可以過。如果為了加快搜索速度,在中間輸入過程中排序,
            再二分很麻煩,速度也快不了多少,因?yàn)橹皇禽斎氲倪^程中需要查找。但是,這個(gè)題其實(shí)很好用map做,代碼量可以少很多,也很簡(jiǎn)潔。
               寫這篇blog的目的是為了提醒自己,容易題再這樣錯(cuò)下去,真的很傷人心,學(xué)什么都沒必要了,當(dāng)時(shí)打算繼續(xù)搞ACM的目的之一就是
            為了提高代碼正確率。這個(gè)題,不僅細(xì)節(jié)部分沒看清楚,而且寫代碼時(shí)候把比較函數(shù)里面的one.nLost寫成了one.nGet,查錯(cuò)了1個(gè)多
            小時(shí),還讓隊(duì)友幫忙查錯(cuò)了好久,真的很無語。寫程序確實(shí)可以debug,但是這也讓我養(yǎng)成了很嚴(yán)重的依賴debug的習(xí)慣。
               人生不可以debug,人生不可以重來。記得以前很多次很多事情就是開始無所謂,后面悲催到底,無限后悔。

               代碼如下:
               1 #include <stdio.h>
              2 #include <string.h>
              3 #include <string>
              4 #include <map>
              5 #include <vector>
              6 #include <algorithm>
              7 #define MAX (100)
              8 using std::map;
              9 using std::string;
             10 using std::vector;
             11 using std::sort;
             12 
             13 struct INFO
             14 {
             15     INFO()
             16     {
             17         nScore = nGet = nLost = 0;
             18     }
             19 
             20     string strName;
             21     int nScore;
             22     int nGet;
             23     int nLost;
             24     bool operator < (const INFO& one) const
             25     {
             26         if (nScore != one.nScore)
             27         {
             28             return nScore > one.nScore;
             29         }
             30         else if (nGet - nLost != one.nGet - one.nLost)//這里把one.nLost寫成了one.nGet
             31         {
             32             return nGet - nLost > one.nGet - one.nLost;
             33         }
             34         else if (nGet != one.nGet)
             35         {
             36             return nGet > one.nGet;
             37         }
             38         else
             39         {
             40             return strName < one.strName;
             41         }
             42     }
             43 };
             44 
             45 int main()
             46 {
             47     int nN;
             48 
             49     //freopen("in.txt", "r", stdin);
             50     //freopen("out.txt", "w", stdout);
             51     while (scanf("%d", &nN) == 1)
             52     {
             53         int nLast = nN * (nN - 1);
             54         char szOne[MAX];
             55         char szTwo[MAX];
             56         int nOne, nTwo;
             57 
             58         map<string, INFO> myMap;
             59         for (int i = 0; i < nLast; ++i)
             60         {
             61             scanf("%s %*s %s %d:%d", szOne, szTwo, &nOne, &nTwo);
             62             //printf("%s %s %d %d\n", szOne, szTwo, nOne, nTwo);
             63             
             64             string strOne = szOne;
             65             myMap[strOne].strName = strOne;
             66             myMap[strOne].nGet += nOne;
             67             myMap[strOne].nLost += nTwo;
             68             
             69             string strTwo = szTwo;
             70             myMap[strTwo].strName = strTwo;
             71             myMap[strTwo].nGet += nTwo;
             72             myMap[strTwo].nLost += nOne;
             73 
             74             if (nOne > nTwo)
             75             {
             76                 myMap[strOne].nScore += 3;
             77             }
             78             else if (nOne == nTwo)
             79             {
             80                 myMap[strOne].nScore += 1;
             81                 myMap[strTwo].nScore += 1;
             82             }
             83             else
             84             {
             85                 myMap[strTwo].nScore += 3;
             86             }
             87         }
             88         
             89         map<string, INFO>::iterator it;
             90         vector<INFO> myVt;
             91         for (it = myMap.begin(); it != myMap.end(); it++)
             92         {
             93             myVt.push_back(it->second);
             94         }
             95         
             96         sort(myVt.begin(), myVt.end());
             97         for (int i = 0; i < myVt.size(); ++i)
             98         {
             99             printf("%s %d\n", myVt[i].strName.c_str(), myVt[i].nScore);
            100         }
            101         printf("\n");
            102     }
            103     
            104     return 0;
            105 }

            posted on 2012-03-14 21:23 yx 閱讀(1361) 評(píng)論(2)  編輯 收藏 引用 所屬分類: 字符串

            評(píng)論

            # re: hdu - 1225:Football Score 2012-03-17 10:44 bigrabbit

            人生不可以debug,人生不可以重來。說得好~  回復(fù)  更多評(píng)論   

            # re: hdu - 1225:Football Score 2012-03-17 18:04 遠(yuǎn)行

            哈哈,有感而發(fā)@bigrabbit
              回復(fù)  更多評(píng)論   

            <2012年7月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            me

            好友

            同學(xué)

            網(wǎng)友

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久婷婷色香五月综合激情| 久久精品中文字幕一区| 成人久久精品一区二区三区| 97久久精品无码一区二区天美| 亚洲国产成人久久综合碰碰动漫3d| 97热久久免费频精品99| 狠狠精品久久久无码中文字幕 | 91精品观看91久久久久久| 久久久久久九九99精品| 婷婷伊人久久大香线蕉AV | 久久国产欧美日韩精品 | 久久九九久精品国产| 久久精品国产99国产精品导航| 精品久久777| 久久www免费人成看片| 91精品无码久久久久久五月天| 97精品依人久久久大香线蕉97| 9191精品国产免费久久| 亚洲成色WWW久久网站| 精品久久久久久无码国产| 97精品国产91久久久久久| 久久综合色老色| 日韩va亚洲va欧美va久久| 青青青国产精品国产精品久久久久| 超级碰碰碰碰97久久久久| 狠狠色综合网站久久久久久久| 成人免费网站久久久| 色偷偷久久一区二区三区| 久久精品国产久精国产果冻传媒| 久久精品国产亚洲Aⅴ香蕉 | 91久久成人免费| 久久福利青草精品资源站免费| 亚洲午夜久久久久妓女影院| 久久综合狠狠综合久久97色| 亚洲国产精品久久| 丰满少妇人妻久久久久久4| 日本久久久久久中文字幕| 久久综合综合久久97色| 久久精品草草草| 精品国产91久久久久久久a| 久久精品一区二区影院 |