# 11007: 【原1007】二哥领工资

### 题目描述

author: xjia 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1007

## Sample Input

``````123.45
543.21
``````

## Sample Output

``````666.66
``````

## FineArtz's solution

``````/* 二哥领工资 */
#include <iostream>
#include <string>
using namespace std;

const int MAXS = 205;
class BigNum{
//friend
friend BigNum operator +(const BigNum&, const BigNum&);
friend ostream& operator <<(ostream&, const BigNum&);
public:
//constructor
//BigNum();
BigNum(const string&);
BigNum(const BigNum&);

//operator
//short& operator [](const int& x) { return data[x]; }
// BigNum& operator =(const BigNum&);

int GetLen() const { return length; }
private:
short data[MAXS];
int length;
};

BigNum::BigNum(const string& s){
for (int i = 0; i != MAXS - 1; ++i)
data[i] = 0;
length = s.size() - 1;
int i = s.size() - 1;
data[1] = s[i--] - '0';
data[2] = s[i] - '0';
for (int j = 3; j <= length; ++j)
data[j] = s[s.size() - j - 1] - '0';

}
BigNum::BigNum(const BigNum& b){
length = b.length;
for (int i = 0; i != MAXS; ++i)
data[i] = b.data[i];
}

ostream& operator <<(ostream& os, const BigNum& b){
for (int i = b.length; i != 2; --i)
os << b.data[i];
os << '.' << b.data[2] << b.data[1];
return os;
}

BigNum operator +(const BigNum& lhs, const BigNum& rhs){
BigNum ans("0.00");
int len = max(lhs.length, rhs.length);
for (int i = 1; i <= len; ++i){
ans.data[i] += lhs.data[i] + rhs.data[i];
if (ans.data[i] >= 10){
ans.data[i] -= 10;
++ans.data[i + 1];
}
}
if (ans.data[len + 1] != 0) ++len;
ans.length = len;
return ans;
}

int main(){
string s1, s2;
cin >> s1 >> s2;
BigNum a(s1), b(s2);
cout << a + b << endl;
return 0;
}
``````

## ligongzzz's solution

``````#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
string ch1, ch2;
cin >> ch1 >> ch2;
auto pos1 = ch1.find('.'), pos2 = ch2.find('.');

auto ch10 = ch1.substr(0, pos1), ch11 = ch1.substr(pos1 + 1);
auto ch20 = ch2.substr(0, pos2), ch21 = ch2.substr(pos2 + 1);

string ans;

auto l1=ch10.length(),l2=ch20.length();
for(int i=0,jw=(atoi(ch11.c_str())+atoi(ch21.c_str())>=100);i<l1||i<l2||jw;++i){
int a = i<ch10.length()?ch10[l1-i-1]-'0':0,b=i<ch20.length()?ch20[l2-i-1]-'0':0;
if(a+b+jw>=10){
ans.push_back(a+b+jw-10+'0');
jw=1;
}else{
ans.push_back(a+b+jw+'0');
jw = 0;
}
}

reverse(ans.begin(),ans.end());
cout<<ans<<".";
printf("%02d\n",(atoi(ch11.c_str())+atoi(ch21.c_str()))%100);

return 0;
}
``````

## yyong119's solution

``````#include <iostream>
#include <cstring>
#include <cstdlib>
char a[202],b[202];
int i,j,k,l,dot1,dot2,maxint,maxfra;
int int1[201],int2[201],fra1[2],fra2[2];
int ansint[201],ansfra[2];
int main(){
using namespace std;
cin>>a>>b;
for (i=0; i<=strlen(a)-1; i++)
if (a[i]=='.') {dot1=i; break;}
for (i=0; i<=strlen(b)-1; i++)
if (b[i]=='.') {dot2=i; break;}
for (i=dot1-1; i>=0; i--) int1[dot1-i-1]=int(a[i]-'0');
for (i=dot1+1; i<=strlen(a)-1; i++) fra1[i-dot1-1]=int(a[i]-'0');
for (i=dot2-1; i>=0; i--) int2[dot2-i-1]=int(b[i]-'0');
for (i=dot2+1; i<=strlen(b)-1; i++) fra2[i-dot2-1]=int(b[i]-'0');
for (i=0; i<=200; i++){
ansint[i]+=int1[i]+int2[i];
if (ansint[i]>=10){ ansint[i+1]+=1; ansint[i]-=10;}
}
ansfra[0]=fra1[0]+fra2[0]; ansfra[1]=fra1[1]+fra2[1];
if (ansfra[1]>=10){ ansfra[0]++; ansfra[1]-=10;}
if (ansfra[0]>=10){ ansfra[0]-=10; ansint[0]++;}
for (i=0; i<=200; i++)
if (ansint[i]>=10) {ansint[i]-=10; ansint[i+1]++;}
for (i=200; i>=0; i--) if (ansint[i]) { maxint=i; break;}
for (i=200; i>=0; i--) if (ansfra[i]) { maxfra=i; break;}
for (i=maxint; i>=0; i--) cout<<ansint[i];
cout<<"."; cout<<ansfra[0]<<ansfra[1];
return 0;
}
``````