#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a, b;
int prim[40] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113};
int x[30], y[30];
int main()
{
while(cin >> a >> b, a != "0" && b != "0")
{
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
int j = 1, k = 1;
for(int i = 0; i < a.size(); i++)
{
if(a[i] != ',')
{
x[j] = x[j] * 10 + a[i] - '0';
}
else
++j;
}
for(int i = 0; i < b.size(); i++)
{
if(b[i] != ',')
y[k] = y[k] * 10 + b[i] - '0';
else
k++;
}
reverse(x+1, x+j+1);
reverse(y+1, y+k+1);
int f = 0;
int m1 = j;
int m2 = k;
int t = 0;
if(m1 > m2)
{
swap(m1, m2);
t = 1;
}
int z[30];
for(int i = 0; i <= m1; i++)
{
z[i] = x[i] + y[i] + f;
f = z[i] / prim[i];
z[i] %= prim[i];
}
z[m1+1] = 0;
for(int i = m1 + 1; i <= m2; i++)
{
int temp = 0;
if(!t)
temp = y[i];
else
temp = x[i];
z[i] = temp + f;
f = z[i] / prim[i];
z[i] %= prim[i];
}
if(f)
z[++m2] = f;
for(int i = m2; i >0; i--)
{
printf(i==m2 ? "%d" : ",%d", z[i]);
}
putchar(10);
}
return 0;
}
HDU 1230 火星 A + B, 进制转换
最新推荐文章于 2017-11-20 12:21:37 发布