import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine())
{
String s1 = sc.nextLine();
if (s1.trim().isEmpty())
break;
String s2 = sc.nextLine();
if (s2.trim().isEmpty())
break;
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder(s1).reverse();
StringBuilder sb2 = new StringBuilder(s2).reverse();
int i = 0;
int prev = 0;
while (i < sb1.length() || i < sb2.length())
{
char c1 = i >= sb1.length() ? '0' : sb1.charAt(i);
char c2 = i >= sb2.length() ? '0' : sb2.charAt(i);
int res = add(c1, c2) + prev;
if (res < 10)
{
sb.append((char) (res + 48));
prev = 0;
}
else if (res < 20)
{
sb.append((char) (res + 87));
prev = 0;
}
else
{
res -= 20;
prev = 1;
char cc = res < 10 ? (char) (res + 48) : (char) (res + 87);
sb.append(cc);
}
i++;
}
if (prev == 1)
{
sb.append('1');
}
System.out.println(sb.reverse());
}
}
static int add(char c1, char c2)
{
int i1 = c1 >= '0' && c1 <= '9' ? c1 - 48 : c1 - 87;
int i2 = c2 >= '0' && c2 <= '9' ? c2 - 48 : c2 - 87;
return i1 + i2;
}
}
ZOJ-1205
最新推荐文章于 2015-07-25 20:45:11 发布