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

               這是個簡單的字符串處理題目。看題目,數據應該不是很大,直接暴力處理可以過。如果為了加快搜索速度,在中間輸入過程中排序,
            再二分很麻煩,速度也快不了多少,因為只是輸入的過程中需要查找。但是,這個題其實很好用map做,代碼量可以少很多,也很簡潔。
               寫這篇blog的目的是為了提醒自己,容易題再這樣錯下去,真的很傷人心,學什么都沒必要了,當時打算繼續搞ACM的目的之一就是
            為了提高代碼正確率。這個題,不僅細節部分沒看清楚,而且寫代碼時候把比較函數里面的one.nLost寫成了one.nGet,查錯了1個多
            小時,還讓隊友幫忙查錯了好久,真的很無語。寫程序確實可以debug,但是這也讓我養成了很嚴重的依賴debug的習慣。
               人生不可以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 閱讀(1350) 評論(2)  編輯 收藏 引用 所屬分類: 字符串

            評論

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

            人生不可以debug,人生不可以重來。說得好~  回復  更多評論   

            # re: hdu - 1225:Football Score 2012-03-17 18:04 遠行

            哈哈,有感而發@bigrabbit
              回復  更多評論   

            <2012年3月>
            26272829123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            公告

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            me

            好友

            同學

            網友

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            99精品国产综合久久久久五月天| 一本一道久久a久久精品综合 | 狠狠色婷婷久久一区二区三区| 久久精品中文字幕有码| 久久久久免费精品国产| 2021久久精品国产99国产精品| 99久久人妻无码精品系列 | 97久久天天综合色天天综合色hd| 久久综合亚洲色一区二区三区| 久久成人永久免费播放| 久久久久免费视频| 亚洲国产高清精品线久久| 成人综合久久精品色婷婷| 久久综合亚洲鲁鲁五月天| 久久青青草原精品国产| 精品久久一区二区| 国产伊人久久| 老男人久久青草av高清| 99久久人妻无码精品系列| 精品乱码久久久久久夜夜嗨| 久久久久国产日韩精品网站| 国内精品久久久久影院亚洲| 亚洲国产精品久久电影欧美| 9久久9久久精品| 久久亚洲国产成人影院网站| 国产美女亚洲精品久久久综合| 狠狠色婷婷久久一区二区三区| 精品久久久久久国产免费了| 久久久久亚洲AV片无码下载蜜桃| 精品久久久久久亚洲精品| 伊人久久大香线蕉影院95| 久久91精品国产91久| MM131亚洲国产美女久久| 日韩电影久久久被窝网| 99久久99久久| 久久久久久久91精品免费观看| 丰满少妇高潮惨叫久久久| 一本久道久久综合狠狠躁AV| 国产V亚洲V天堂无码久久久| 欧美日韩精品久久免费| 久久久久人妻一区精品|