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

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


            国产激情久久久久影院老熟女免费| 亚洲AV成人无码久久精品老人 | 久久久久青草线蕉综合超碰| 欧美精品乱码99久久蜜桃| 中文字幕日本人妻久久久免费| 国产美女久久精品香蕉69| 精品人妻伦一二三区久久| 亚洲精品乱码久久久久久中文字幕| 成人久久精品一区二区三区| 亚洲午夜精品久久久久久app| 久久精品国产99国产精品澳门| 四虎亚洲国产成人久久精品| 国产精品一久久香蕉国产线看| 国产精品成人久久久| 国产成人无码精品久久久免费 | 久久久久99精品成人片三人毛片| 久久精品中文字幕一区| 国产亚洲色婷婷久久99精品91| 99国产欧美精品久久久蜜芽| 日本精品久久久久影院日本| 久久精品一区二区| 久久婷婷五月综合国产尤物app| 性做久久久久久久久久久| 日韩欧美亚洲综合久久影院d3| 久久偷看各类wc女厕嘘嘘| 伊人久久大香线蕉综合Av| 久久这里只有精品视频99| 国产精品99久久不卡| 国产精品嫩草影院久久| 色综合久久中文色婷婷| 久久国产精品成人影院| 久久综合久久自在自线精品自| 国内精品久久国产| 久久国产精品无| 中文字幕精品久久久久人妻| 少妇久久久久久被弄到高潮| 久久久久久极精品久久久| 亚洲AⅤ优女AV综合久久久| 亚洲国产精品无码久久青草 | 欧美伊人久久大香线蕉综合 | 国内精品久久久久久99蜜桃|