package org.lei.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BigData {
static void reverse(char s[],int len)
{
int i=0;
char swap;
while(i<len/2)
{
swap=s[i];
s[i]=s[len-1-i];
s[len-1-i]=swap;
i++;
}
}
static void reverse(int s[],int len)
{
int i=0;
int swap;
while(i<len/2)
{
swap=s[i];
s[i]=s[len-1-i];
s[len-1-i]=swap;
i++;
}
}
static void add(String n1,String n2){
char []num1 = n1.toCharArray();
char []num2 = n2.toCharArray();
int len1 = num1.length;
int len2 = num2.length;
reverse(num1, len1);
reverse(num2, len2);
int max = len1>len2?len1:len2;
int min = len1<len2?len1:len2;
int []sum = new int[max+1];
int c = 0;
int i = 0;
for(;i<min;i++){
sum[i] = Integer.valueOf(num1[i]+"")+Integer.valueOf(num2[i]+"")+c;
if (sum[i]>=10) {
c = 1;
sum[i]-=10;
}else {
c = 0;
}
}
for (i = min; i<max; i++) {
if (len1<len2) {
sum[i] = Integer.valueOf(num2[i]+"")+c;
if(sum[i]>=10){
sum[i] -= 10;
c = 1;
}else {
c = 0;
}
}else if(len2<len1){
sum[i] = Integer.valueOf(num1[i]+"")+c;
if(sum[i]>=10){
sum[i] -= 10;
c = 1;
}else {
c = 0;
}
}
}
sum[i] +=c;
reverse(sum, sum.length);
for(int j = 0;j<sum.length;j++){
if(sum[0]==0&&j == 0){
continue;
}
System.out.print(sum[j]);
}
}
public static void main(String []args){
String n1 = "9999567";
String n2 = "834";
add(n1, n2);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BigData {
static void reverse(char s[],int len)
{
int i=0;
char swap;
while(i<len/2)
{
swap=s[i];
s[i]=s[len-1-i];
s[len-1-i]=swap;
i++;
}
}
static void reverse(int s[],int len)
{
int i=0;
int swap;
while(i<len/2)
{
swap=s[i];
s[i]=s[len-1-i];
s[len-1-i]=swap;
i++;
}
}
static void add(String n1,String n2){
char []num1 = n1.toCharArray();
char []num2 = n2.toCharArray();
int len1 = num1.length;
int len2 = num2.length;
reverse(num1, len1);
reverse(num2, len2);
int max = len1>len2?len1:len2;
int min = len1<len2?len1:len2;
int []sum = new int[max+1];
int c = 0;
int i = 0;
for(;i<min;i++){
sum[i] = Integer.valueOf(num1[i]+"")+Integer.valueOf(num2[i]+"")+c;
if (sum[i]>=10) {
c = 1;
sum[i]-=10;
}else {
c = 0;
}
}
for (i = min; i<max; i++) {
if (len1<len2) {
sum[i] = Integer.valueOf(num2[i]+"")+c;
if(sum[i]>=10){
sum[i] -= 10;
c = 1;
}else {
c = 0;
}
}else if(len2<len1){
sum[i] = Integer.valueOf(num1[i]+"")+c;
if(sum[i]>=10){
sum[i] -= 10;
c = 1;
}else {
c = 0;
}
}
}
sum[i] +=c;
reverse(sum, sum.length);
for(int j = 0;j<sum.length;j++){
if(sum[0]==0&&j == 0){
continue;
}
System.out.print(sum[j]);
}
}
public static void main(String []args){
String n1 = "9999567";
String n2 = "834";
add(n1, n2);
}
}