• <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
            除以 1000 , 對余數(shù)進(jìn)行處理
             1 #include <iostream>
             2 using namespace std;
             3 
             4 char* reverse(char* s, int low, int high)
             5 {
             6     while (low < high)
             7     {
             8         s[low] ^= s[high];
             9         s[high] ^= s[low];
            10         s[low] ^= s[high];
            11         ++low;
            12         --high;
            13     }
            14     return s;
            15 }
            16 
            17 char* format_thousands_separator(char a[], unsigned long val)
            18 {
            19     char* ret = a;
            20     char temp[4];
            21     int t;
            22     int n = 0;
            23     while (val > 1000)
            24     {
            25         t = val % 1000;
            26         if (t >= 100)
            27         {
            28             itoa(t, temp, 10);
            29             reverse(temp, 02);
            30             //cout << temp << endl;
            31             strcat(ret, temp);
            32             //cout<< "test" << ret << endl;
            33         }
            34         else if (t >= 10)
            35         {
            36             itoa(t, temp, 10);
            37             reverse(temp, 01);
            38             strcat(ret, temp);
            39             strcat(ret, "0");
            40         }
            41         else
            42         {
            43             itoa(t, temp, 10);
            44             strcat(ret, temp);
            45             strcat(ret, "00");
            46         }
            47         strcat(ret, ",");
            48         n += 4;
            49         val /= 1000;
            50         ret[n] = '\0';
            51         cout << ret << endl;
            52     }
            53     if (val >= 100)
            54     {
            55         itoa(val, temp, 10);
            56         reverse(temp, 02);
            57         strcat(ret, temp);
            58         n += 3;
            59     }
            60     else if (val >= 10)
            61     {
            62         itoa(val, temp, 10);
            63         reverse(temp, 01);
            64         strcat(ret, temp);
            65         n += 2;
            66     }
            67     else
            68     {
            69         itoa(val, temp, 10);
            70         strcat(ret, temp);
            71         ++n;
            72     }
            73     reverse(ret, 0, n - 1);
            74     ret[n] = '\0';
            75     return ret;
            76 };
            77 
            78 int main()
            79 {
            80     unsigned long ul;
            81     char sul[20= {0};
            82     while (cin >> ul)
            83     {
            84         cout << format_thousands_separator(sul, ul) << endl;
            85     }
            86     return 0;
            87 }

            先轉(zhuǎn)換成一個 字符串 ,然后從右掃描,加逗號,然后反轉(zhuǎn)
             1 #include <iostream>
             2 #include <sstream>
             3 #include <string>
             4 #include <algorithm>
             5 using namespace std;
             6 
             7 const string& format_thousands_separator(string& s, unsigned long val)
             8 {
             9     s.clear();
            10     char t[20];
            11     string temp(ltoa(val, t, 10));
            12 
            13     int n = 0;
            14     for (string::const_reverse_iterator cit = temp.rbegin(); cit != temp.rend(); ++cit)
            15     {
            16         ++n;
            17         s += *cit;
            18         if (n == 3)
            19         {
            20             s += ',';
            21             n = 0;
            22         }
            23     }
            24     reverse(s.begin(), s.end());
            25     return s;
            26 }
            27 
            28 int main()
            29 {
            30     unsigned long ul;
            31     string sul;
            32     while (cin >> ul)
            33     {
            34         cout << format_thousands_separator(sul, ul) << endl;
            35     }
            36     return 0;
            37 }

            http://m.shnenglu.com/qinqing1984/archive/2011/06/24/149366.html





            posted on 2011-06-24 16:46 unixfy 閱讀(483) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久精品欧美日韩精品| 成人久久精品一区二区三区| 一级做a爰片久久毛片免费陪| 久久伊人五月丁香狠狠色| 久久久久久久人妻无码中文字幕爆 | 久久er99热精品一区二区| 亚洲国产精品久久久久| 国产偷久久久精品专区 | 91麻精品国产91久久久久| 久久午夜综合久久| 久久99精品久久久久婷婷| 四虎国产精品免费久久| 色综合久久综合网观看| 久久久无码人妻精品无码| 综合久久精品色| 国产精品美女久久久网AV| 久久久久99精品成人片试看| 久久香蕉国产线看观看猫咪?v| 91精品国产色综合久久| 日本欧美久久久久免费播放网| 久久精品18| 中文字幕成人精品久久不卡| 亚洲乱码中文字幕久久孕妇黑人| 欧美国产成人久久精品| 国产精品毛片久久久久久久| 久久偷看各类wc女厕嘘嘘| 香蕉久久久久久狠狠色| 亚洲国产精品无码久久九九| 国产亚洲色婷婷久久99精品91| 国产精品欧美久久久天天影视| 精品久久久久久无码专区| 久久天天躁狠狠躁夜夜网站| 亚洲国产精品无码久久久不卡| 久久久精品人妻一区二区三区蜜桃| 欧美日韩中文字幕久久久不卡| 久久精品国产亚洲av瑜伽| 国产福利电影一区二区三区,免费久久久久久久精 | 久久久一本精品99久久精品66| 久久亚洲AV无码精品色午夜麻豆 | 狠狠色婷婷久久综合频道日韩| 久久久亚洲AV波多野结衣|