• <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 - 0,comments - 0,trackbacks - 0
            #include <iostream>Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

            Input

            Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

            Output

            For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

            Sample Input
            -1000000 9 
            Sample Output
            -999,991
            這道題我提交了三次,第一次提交之后顯示部分正確,檢查了代碼發(fā)現(xiàn)輸出負(fù)號(hào)之后沒有對(duì)數(shù)進(jìn)行處理,即后來判斷時(shí)-100000也小于1000啊。
            改了之后提交第二次,測(cè)試結(jié)果正確的次數(shù)多了,還是部分錯(cuò)誤,我又檢查了一下,用了幾個(gè)特殊的數(shù)來試,發(fā)現(xiàn)100000輸出的結(jié)果是100,0,因?yàn)闆]有考慮后面的數(shù)字可能會(huì)發(fā)生沒有三位但是卻沒有自動(dòng)補(bǔ)全0的情況。如果這個(gè)時(shí)候仍然使用使用C++可能麻煩很多,就想著要利用C語(yǔ)言的printf的輸出固定格式,沒有達(dá)到自動(dòng)補(bǔ)全0,修改之后提交通過。
            下面貼我的代碼:
            #include <iostream>
            using namespace std;
            int main(void){
                
            int a,b;
                
            int sum=0;
                
            while(cin>>a>>b){
                    sum
            =a+b;
                    
            if(sum<0){
                        sum
            =-sum;      
                        cout
            <<"-";
                    }
                    
            if(sum<1000)
                    cout
            <<sum;
                    
            else if(sum>=1000&&sum<1000000)
                        printf(
            "%d,%03d",(sum/1000),sum%1000);
                    
            else if(sum>=1000000)
                        printf(
            "%d,%03d,%03d",sum/1000000,((sum%1000000)/1000),sum%1000);
                }
                
            return 0;
            }

            posted on 2014-07-26 10:40 兔兔的天空之城 閱讀(122) 評(píng)論(0)  編輯 收藏 引用

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


            久久免费美女视频| 久久精品国产AV一区二区三区| 97久久久久人妻精品专区 | 久久久精品午夜免费不卡| 国产成人精品久久| 人妻无码精品久久亚瑟影视| 久久精品国产亚洲av高清漫画| 国产午夜精品久久久久九九| 三上悠亚久久精品| 久久露脸国产精品| 国产91色综合久久免费分享| 欧美亚洲国产精品久久久久| 一本大道加勒比久久综合| 久久精品午夜一区二区福利 | AV色综合久久天堂AV色综合在| 国产精品成人99久久久久 | 久久99精品久久久久久秒播 | 77777亚洲午夜久久多喷| 日本免费久久久久久久网站| 久久夜色精品国产噜噜亚洲a| 久久se精品一区二区| 久久久久久精品成人免费图片| 久久精品国产只有精品2020| A级毛片无码久久精品免费| 久久久久国产| 亚洲一区中文字幕久久| 国产精品美女久久久| 人人妻久久人人澡人人爽人人精品 | 久久精品国产一区二区| 麻豆精品久久精品色综合| 97久久国产亚洲精品超碰热| 亚洲精品tv久久久久久久久| 久久精品国产精品亚洲精品 | 久久中文字幕精品| 久久国产精品无| 久久国语露脸国产精品电影| 伊人久久大香线蕉av一区| 久久男人Av资源网站无码软件| 日韩人妻无码精品久久免费一| 久久夜色精品国产噜噜麻豆| 久久久国产精品亚洲一区|