ZOJ Problem Set - 1205

ZOJ Problem Set - 1205

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=205

 

程序语言在发展,题目却没有。

http://student.csdn.net/space.php?uid=238923&do=blog&id=33085

 

自己也写了一个,练练手。

 

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int getINT(char ch) {
    if(ch >= '0' && ch <= '9') {
        return ch - '0';
    } else if(ch >= 'a' && ch <= 'j') {
        return ch - 'a' + 10;
    }
    //return;
}

char getCHAR(int n) {
    if(n >= 0 && n <10) {
        return char('0' + n);
    } else if(n > 9 && n<20) {
        return char('a' + (n - 10));
    }
    //return;
}

int main()
{
    string str1, str2;
    int loop1, loop2;
    int MR, tmp;
    vector<int> A;
    vector<int>::iterator iA;
    vector<int> B;
    vector<int>::iterator iB;
    vector<int> SUM;
    while(cin >> str1 >> str2) {
        A.clear();
        B.clear();
        SUM.clear();
        MR = 0;
        for(loop1 = str1.size(), loop2 = str2.size();
        loop1 > 0 || loop2 > 0; loop1--,loop2--) {
            if(loop1 > 0) {
                A.insert(A.begin(), getINT(str1[loop1-1]));
            }
            if(loop2 > 0) {
                B.insert(B.begin(), getINT(str2[loop2-1]));
            }
        }
        for(iA = A.end() - 1, iB = B.end() - 1;
        iA >= A.begin() && iB >= B.begin(); iA--, iB--) {
            tmp = *iA + *iB + MR;
            MR = tmp / 20;
            tmp = tmp % 20;
            SUM.insert(SUM.begin(), tmp);
        }
        if(iA >= A.begin()) {
            for(;iA >= A.begin(); iA--) {
                tmp = *iA + MR;
                MR = tmp / 20;
                tmp = tmp % 20;
                SUM.insert(SUM.begin(), tmp);
            }
        }
        if(iB >= B.begin()) {
            for(;iB >= B.begin(); iB--) {
                tmp = *iB + MR;
                MR = tmp / 20;
                tmp = tmp % 20;
                SUM.insert(SUM.begin(), tmp);
            }
        }
        if(MR) {
            SUM.insert(SUM.begin(), MR);
        }
        for(vector<int>::iterator It = SUM.begin();
        It < SUM.end(); It++) {
            cout << getCHAR(*It);
        }
        cout << endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值