• <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
            這道題我提交了三次,第一次提交之后顯示部分正確,檢查了代碼發現輸出負號之后沒有對數進行處理,即后來判斷時-100000也小于1000啊。
            改了之后提交第二次,測試結果正確的次數多了,還是部分錯誤,我又檢查了一下,用了幾個特殊的數來試,發現100000輸出的結果是100,0,因為沒有考慮后面的數字可能會發生沒有三位但是卻沒有自動補全0的情況。如果這個時候仍然使用使用C++可能麻煩很多,就想著要利用C語言的printf的輸出固定格式,沒有達到自動補全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)  編輯 收藏 引用
            久久久久国产视频电影| 久久久久99精品成人片试看| 色综合合久久天天综合绕视看| 青青草原综合久久大伊人精品| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久99精品久久只有精品| 99国产欧美久久久精品蜜芽| 久久精品中文字幕第23页| 无码任你躁久久久久久老妇App| 久久精品国产第一区二区三区| 久久国产V一级毛多内射| 久久91精品国产91久| 国产成人精品久久亚洲高清不卡 | 青青热久久国产久精品 | 久久国产香蕉一区精品| 午夜久久久久久禁播电影| 久久精品18| 国产精品久久久天天影视| 伊人久久综合精品无码AV专区| 色噜噜狠狠先锋影音久久| 午夜精品久久久久久久久| 无码任你躁久久久久久久| 免费精品99久久国产综合精品| 97精品伊人久久久大香线蕉 | 久久综合狠狠综合久久97色| AV无码久久久久不卡蜜桃| 久久中文骚妇内射| 亚洲AV日韩精品久久久久久久| 欧美久久久久久午夜精品| 精品久久久久久久中文字幕| 97精品久久天干天天天按摩| 人人狠狠综合久久88成人| 亚洲国产美女精品久久久久∴| 狠狠色综合网站久久久久久久高清| 久久青青草原精品国产软件| 久久狠狠一本精品综合网| 久久综合色之久久综合| 午夜精品久久久久成人| 久久久久久国产精品无码下载| 国产毛片欧美毛片久久久| 久久国产亚洲高清观看|