• <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
              回復  更多評論   

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            公告

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            me

            好友

            同學

            網友

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产亚洲色婷婷久久99精品| 亚洲欧美成人综合久久久| 91久久精品国产91性色也| 国产精品美女久久久免费| 人人狠狠综合88综合久久| 99久久国产宗和精品1上映| 99久久无色码中文字幕| 久久久久亚洲AV成人网人人网站 | 精品久久久久久中文字幕人妻最新| 久久99精品久久久久婷婷| 久久国产福利免费| 激情伊人五月天久久综合| 久久无码人妻精品一区二区三区 | 国内精品伊人久久久久av一坑| 狠狠色婷婷综合天天久久丁香| 香蕉99久久国产综合精品宅男自 | 国产亚洲美女精品久久久| 久久精品国产99国产精品导航| 国产成人久久精品区一区二区| 无码国内精品久久人妻麻豆按摩| 国产精品福利一区二区久久| 欧美精品国产综合久久| 久久久精品日本一区二区三区 | 老男人久久青草av高清| 91精品国产91久久久久久| 久久久久亚洲精品无码蜜桃| 久久香蕉国产线看观看猫咪?v| 久久这里只有精品久久| 久久综合国产乱子伦精品免费| 久久99国产精品久久99小说 | 亚洲Av无码国产情品久久| 色综合久久综合网观看| 久久精品水蜜桃av综合天堂| 亚洲级αV无码毛片久久精品| 欧美日韩久久中文字幕| 精品国产青草久久久久福利| 亚洲а∨天堂久久精品| 无码任你躁久久久久久久| 久久综合给合综合久久| 欧美日韩久久中文字幕| 丁香色欲久久久久久综合网|