• <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ù)號之后沒有對數(shù)進(jìn)行處理,即后來判斷時(shí)-100000也小于1000啊。
            改了之后提交第二次,測試結(jié)果正確的次數(shù)多了,還是部分錯(cuò)誤,我又檢查了一下,用了幾個(gè)特殊的數(shù)來試,發(fā)現(xiàn)100000輸出的結(jié)果是100,0,因?yàn)闆]有考慮后面的數(shù)字可能會發(fā)生沒有三位但是卻沒有自動(dòng)補(bǔ)全0的情況。如果這個(gè)時(shí)候仍然使用使用C++可能麻煩很多,就想著要利用C語言的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 兔兔的天空之城 閱讀(121) 評論(0)  編輯 收藏 引用

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


            亚洲国产另类久久久精品小说| 精品一区二区久久久久久久网站| 精品久久久久久无码国产| 久久亚洲国产中v天仙www| 久久精品国产精品亚洲| 久久婷婷五月综合国产尤物app| 伊人久久久AV老熟妇色| 伊人久久精品线影院| 久久婷婷国产剧情内射白浆| 久久AV高清无码| 色综合合久久天天给综看| 亚洲级αV无码毛片久久精品| 人人狠狠综合久久亚洲婷婷| 久久综合久久鬼色| 青青热久久综合网伊人| 久久中文字幕精品| 情人伊人久久综合亚洲| 亚洲综合熟女久久久30p| 久久青青草原精品国产不卡| 中文字幕乱码人妻无码久久| 久久影院久久香蕉国产线看观看| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久免费视频一区| avtt天堂网久久精品| 久久人与动人物a级毛片| 久久精品夜色噜噜亚洲A∨| 99久久精品午夜一区二区| 久久人人爽人人爽人人片AV麻烦| 久久国产精品偷99| 伊人久久综合热线大杳蕉下载| 麻豆成人久久精品二区三区免费 | 久久久久久精品久久久久| 久久99热这里只有精品国产| 色综合久久精品中文字幕首页 | 无码任你躁久久久久久老妇App| 久久免费精品视频| 久久亚洲综合色一区二区三区| av无码久久久久不卡免费网站| 国产精品美女久久久久网| 国产精品久久久天天影视| 国产99久久精品一区二区|