杭电1002 A + B Problem II

#include<iostream>
#include <string>
using namespace std;
/*
int main()
{
    int sum[1000];
    int temp=0;
    string aL;
    string bL;
    int n1,n2,n,tem;
    int k,t=1,u,v;
    cin >> k;
    for (int w = 0; w < k; w++)
    {
            cin >> aL >> bL;
            n1 = aL.length();
            n2 = bL.length();
            int sum[1000];
            int q;
            tem = abs(n1 - n2);
            if (n1>=n2)
            {
                q = 0;
                int i = n2 - 1;
                //cout << "已运行flag1" << endl;
                while (i>=0)
                {
                    if (aL[i + tem]-48 + bL[i]-48 +temp>= 10)
                    {
                        //cout << aL[i + tem]-48<< " " << bL[i]-48 << " "<<temp<<" "<<i<<endl;
                        sum[q++] = (aL[i + tem]-48 + bL[i]-48+temp) % 10;
                        //cout << sum[q-1] << endl;
                        temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10; 
                    }
                    else
                    {
                        //cout << aL[i + tem]-48 << " " << bL[i]-48 << " " << temp <<" "<< i<<endl;
                        sum[q++] = aL[i + tem]-48 + bL[i]-48+temp;
                        //cout << sum[q - 1] << endl;
                        temp = (aL[i + tem]-48 + bL[i]-48 + temp) / 10; 
                    }
                    u = tem;
                    i--;
                }
                if ((u==0)&&(temp !=0))
                {
                    sum[q++] = temp;
                    //cout << sum[q - 1] << endl;
                    temp = 0;
                }
                while (u >0)
                {
                       //cout << aL[u - 1]-48 << " " << temp <<" "<<u<< endl;
                        sum[q++] = (aL[u-1]-48 + temp) % 10;
                        //cout << sum[q - 1] << endl;
                        temp = (aL[u - 1]-48 + temp) / 10;;
                        u--;
                }
                if (temp !=0)
                {
                    sum[q++] = temp;
                    //cout << sum[q - 1] << endl;
                    temp = 0;
                }       
            }
            if (n1<n2)
            {
                q = 0;
                int i= n1 - 1;
                //cout << "已运行flag2" << endl;
                while(i>=0)
                {
                    if (bL[i + tem]-48 + aL[i]-48+temp >= 10)
                    {
                        //cout << bL[i + tem]-48 << " " << aL[i]-48 <<" "<<temp<<" "<< i<<endl;
                        sum[q++] = (bL[i + tem]-48 + aL[i]-48+temp) % 10;
                        //cout << sum[q-1] << endl;
                        temp = 1;
                    }
                    else
                    {
                        //cout << bL[i + tem]-48 << " " << aL[i]-48 << " " << temp <<" "<<i<< endl;
                        sum[q++] = bL[i + tem]-48 + aL[i]-48+temp;
                        //cout << sum[q-1] << endl;
                        temp = (bL[i + tem]-48 + aL[i]-48 + temp) / 10;
                    }
                    v = tem;
                    i--;
                }
                if ((v == 0) && (temp != 0))
                {
                    sum[q++] = temp;
                    temp = 0;
                }
                    while (v>0)
                    {
                        //cout << bL[v - 1]-48 << " " << temp <<" "<< v<<endl;
                        sum[q++] = (bL[v-1]-48 + temp) % 10;
                        //cout << sum[q-1] << endl;
                        temp = (bL[v-1]-48 + temp) / 10;
                        v--;
                    }
                    if (temp !=0)
                    {
                        sum[q++] = temp;
                        temp = 0;
                    }


            }
            cout << "Case" << " " << w + 1 << ":" << endl;
            cout << aL<<" + "<<bL<<" = ";
            //cout << " " << "+" << " ";
            //cout << bL;
            //cout << " " << "=" << " ";
            for (int i = q-1; i>=0; i--)
            {
                //cout << t++ << endl;
                cout << sum[i];

            }
            cout << endl;
            if (w < k- 1) cout << endl;
            //cout <<"\n"<< endl;
    }
    return 0;

}*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值