• <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
            計(jì)算兩個(gè)1000位以內(nèi)整數(shù)的和
            輸入
            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 幽幽 閱讀(1007) 評(píng)論(2)  編輯 收藏 引用 所屬分類: HDOJ日志

            FeedBack:
            # re: hdoj1002
            2008-08-21 19:59 | zhou
            幫我看看,我哪里錯(cuò)了?
            #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;
            }  回復(fù)  更多評(píng)論
              
            # re: hdoj1002
            2008-08-25 08:20 | 幽幽
            以后這種題,還是用java來做吧.........  回復(fù)  更多評(píng)論
              

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



            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(6)

            隨筆分類(35)

            隨筆檔案(51)

            文章分類(3)

            文章檔案(3)

            相冊(cè)

            我的鏈接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久96国产精品久久久| 久久笫一福利免费导航| 久久无码av三级| 国产女人aaa级久久久级| 三级片免费观看久久| 中文字幕久久精品无码| 99久久免费只有精品国产| 香蕉99久久国产综合精品宅男自 | 久久精品国产精品国产精品污| 久久精品视频网| 99久久国产亚洲综合精品| 久久天堂电影网| 亚洲国产精品18久久久久久| 国产精品成人久久久久三级午夜电影| 亚洲精品WWW久久久久久| 91精品国产9l久久久久| 久久99国产综合精品女同| 久久91这里精品国产2020| 精品久久777| 色偷偷88888欧美精品久久久| 精品水蜜桃久久久久久久| 亚洲av成人无码久久精品| 亚洲精品国产自在久久| 国产成人精品久久综合| 国产精品久久影院| 久久精品国产亚洲AV忘忧草18| 久久99久久成人免费播放| 免费精品99久久国产综合精品| 亚洲成色WWW久久网站| 亚洲天堂久久久| 久久久午夜精品| 欧美日韩精品久久免费| 久久婷婷午色综合夜啪| 综合久久精品色| 国内精品伊人久久久久777| 久久久国产打桩机| 国产A级毛片久久久精品毛片| 2021国内精品久久久久久影院| 少妇无套内谢久久久久| 久久午夜无码鲁丝片秋霞| 日产精品久久久久久久|