• <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 - 51,  comments - 28,  trackbacks - 0

            A + B Problem II
            計算兩個1000位以內整數的和
            輸入
            2
            1 2
            112233445566778899 998877665544332211

            輸出
            Case 1:
            1 + 2 = 3

            Case 2:
            112233445566778899 + 998877665544332211 = 1111111111111111110

            #include <iostream>
             
            using namespace std;

            int main()
            {
                
            int T, count_T;
                
            char a[1001], b[1001], ans[1002];
                cin 
            >> T;
                
            for(count_T=1; count_T <= T; count_T++{
                    cin 
            >> a >> b;
                    
            if(count_T==1{
                        cout 
            << "Case " << count_T << ":" << endl;
                    }

                    
            else {
                        cout 
            << "\nCase " << count_T << ":" << endl;
                    }

                    cout 
            << a << " + " << b << " = ";
                    
            int la=strlen(a)-1, lb=strlen(b)-1, sign=0, i;
                    
            for(i=0;la>=0 && lb>=0; la--,lb--,i++{
                        sign 
            += a[la] + b[lb] - '0' - '0';
                        ans[i] 
            = sign % 10;
                        sign 
            /= 10;
                    }

                    
            for(; la>=0; la--, i++{
                        sign 
            += a[la] - '0';
                        ans[i] 
            = sign % 10;
                        sign 
            /= 10;
                    }

                    
            for(; lb>=0; lb--, i++{
                        sign 
            += b[lb] - '0';
                        ans[i] 
            = sign % 10;
                        sign 
            /= 10;
                    }

                    
            if(sign) {
                        ans[i] 
            = sign;
                        i
            ++;
                    }

                    
            for(i--; i>=0; i--{
                        cout 
            << (char)(ans[i] + '0');
                    }

                    cout 
            << endl;
                }

                
            return(0);
            }

            posted on 2008-02-12 15:38 幽幽 閱讀(1008) 評論(2)  編輯 收藏 引用 所屬分類: HDOJ日志

            FeedBack:
            # re: hdoj1002
            2008-08-21 19:59 | zhou
            幫我看看,我哪里錯了?
            #include<stdio.h>
            #include<string.h>
            int main()
            {
            int T, n, la, lb, i;
            char a[1001], b[1001];
            int c[1002];
            scanf("%d", &T);
            for(n = 1; n <= T; n++)
            {
            scanf("%s %s", &a, &b);
            if(n == 1)
            {
            printf("Case %d:\n", n);
            printf("%s + %s = ", a, b);
            }
            else
            {
            printf("\nCase %d:\n", n);
            printf("%s + %s = ", a, b);
            }
            la = strlen(a) - 1; lb = strlen(b) - 1;
            memset(c, 0, sizeof(c));
            for(i = 0; la >= 0 &&lb >= 0; la--, lb--, i++)
            {
            c[i] = a[la] - '0' + b[lb] - '0';
            if(c[i] > 9)
            {
            c[i+1] += c[i]/10;
            c[i] %= 10;
            }
            }
            for( ;la >= 0; la--, i++)
            {
            c[i] = c[la] - '0';
            if(c[i] > 9)
            {
            c[i+1] += c[i]/10;
            c[i] %= 10;
            }
            }
            for( ;lb >= 0; lb--, i++)
            {
            c[i] = c[lb] - '0';
            if(c[i] > 9)
            {
            c[i+1] += c[i]/10;
            c[i] %= 10;
            }
            }
            for(i--; i >= 0; i--)
            printf("%d", c[i]);
            printf("\n");
            }
            return 0;
            }  回復  更多評論
              
            # re: hdoj1002
            2008-08-25 08:20 | 幽幽
            以后這種題,還是用java來做吧.........  回復  更多評論
              

            <2008年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(6)

            隨筆分類(35)

            隨筆檔案(51)

            文章分類(3)

            文章檔案(3)

            相冊

            我的鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            狠狠色婷婷综合天天久久丁香| 国产成人久久AV免费| 九九热久久免费视频| 精品国产热久久久福利| 国产精品久久久久久久久软件| 久久精品亚洲一区二区三区浴池 | 97久久超碰成人精品网站| 狠狠色丁香久久婷婷综| 久久综合成人网| 国产精品无码久久久久久| 久久精品亚洲男人的天堂| 亚洲欧美日韩久久精品第一区| 久久精品国产亚洲网站| 亚洲综合精品香蕉久久网| 亚洲综合久久综合激情久久 | 久久青青色综合| 丰满少妇高潮惨叫久久久| 久久青青草视频| 欧美日韩中文字幕久久久不卡| 中文字幕无码免费久久| 一本久久a久久精品综合香蕉| 久久精品人成免费| 久久无码国产专区精品| 久久播电影网| 精品久久久久久无码中文字幕| 99国产欧美久久久精品蜜芽| 婷婷五月深深久久精品| 久久久久av无码免费网| 欧美伊人久久大香线蕉综合69| 久久精品成人免费网站| 久久精品国产秦先生| 国产精品久久精品| 久久人妻少妇嫩草AV无码专区| 久久精品国产亚洲AV不卡| 久久综合一区二区无码| 日韩十八禁一区二区久久| 国产免费久久精品丫丫| 久久精品国产99国产精品| 久久99精品国产99久久6| 精品久久久久久久久久中文字幕| 国产69精品久久久久9999|