• <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久久久久| 亚洲国产成人精品女人久久久| 色婷婷噜噜久久国产精品12p | 国产A级毛片久久久精品毛片| 日日躁夜夜躁狠狠久久AV| 品成人欧美大片久久国产欧美| 一级a性色生活片久久无| www久久久天天com| 久久精品人妻一区二区三区| 亚洲色欲久久久综合网| 国产精品美女久久久久av爽| 亚洲午夜久久久久久久久久| 国产亚洲色婷婷久久99精品91| 三上悠亚久久精品| 很黄很污的网站久久mimi色 | AV无码久久久久不卡网站下载 | avtt天堂网久久精品| 日韩一区二区三区视频久久| 热久久国产精品| 国产精品免费福利久久| 99久久香蕉国产线看观香| 国产亚洲色婷婷久久99精品91| 人妻无码αv中文字幕久久| 四虎影视久久久免费| 久久综合综合久久狠狠狠97色88| 中文字幕精品久久| 久久久久久青草大香综合精品| 狠狠色丁香婷婷综合久久来| 久久久久成人精品无码中文字幕| 色婷婷狠狠久久综合五月| 久久精品一区二区三区中文字幕| 久久r热这里有精品视频| 久久久久亚洲AV无码麻豆| 亚洲国产精品久久电影欧美| 久久久亚洲AV波多野结衣 | 久久精品国产亚洲av水果派| 久久一日本道色综合久久|