package com.java.mytry;
import java.util.Scanner;
import javafx.collections.ListChangeListener.Change;
/**
* 大数相乘
* @author Dong
*
*/
public class Mulyiplication_of_large_Number {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str1 = in.next();
String str2 = in.next();
int len1 = str1.length();
int len2 = str2.length();
char[] s1 = str1.toCharArray();
char[] s2 = str2.toCharArray();
Change(len1,s1);
Change(len2,s2);
System.out.println( str1);
System.out.println(" * ");
System.out.println( str2);
System.out.println( " = ");
Mulyiplication(s1,len1,s2,len2);
}
/**
* 逐位相乘
* @param s1 乘数
* @param len1 乘数长度
* @param s2 被乘数
* @param len2 被乘数长度
*/
private static void Mulyiplication(char[] s1, int len1, char[] s2, int len2) {
//两位乘积位数
int size = len1 +len2 +3;
int []result = new int[size];
for(int i = 0;i<size;i++){
result[i] = 0;
}
//逐位相乘
for(int i = 0;i<len2;i++){
for(int j=0;j<len1;j++){
result[i+j] += (int)(s2[i]-'0') * (int)(s1[j]-'0') ;
}
}
for(int i = 0;i<size;i++){
int carry = result[i]/10;
result[i] = result[i]%10;
if(carry>0)
result[i+1] += carry;
}
int i;
for( i = size-1;i>=0;i--){
if(result[i] > 0)
break;
}
for(int j = 0;j<=i;j++){
System.out.print(result[i-j]);
}
}
/**
* 字符数组倒置
* @param len 数组长度
* @param s 需要倒置的数组
*/
private static void Change(int len, char[] s) {
//高低位对调
for(int i = 0;i<len/2;i++){
s[i] += s[len - 1 - i];
s[len - 1 - i] = (char)(s[i] - s[len - 1 - i]);
s[i] = (char)(s[i] - s[len - 1 - i]);
}
}
}
import java.util.Scanner;
import javafx.collections.ListChangeListener.Change;
/**
* 大数相乘
* @author Dong
*
*/
public class Mulyiplication_of_large_Number {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str1 = in.next();
String str2 = in.next();
int len1 = str1.length();
int len2 = str2.length();
char[] s1 = str1.toCharArray();
char[] s2 = str2.toCharArray();
Change(len1,s1);
Change(len2,s2);
System.out.println( str1);
System.out.println(" * ");
System.out.println( str2);
System.out.println( " = ");
Mulyiplication(s1,len1,s2,len2);
}
/**
* 逐位相乘
* @param s1 乘数
* @param len1 乘数长度
* @param s2 被乘数
* @param len2 被乘数长度
*/
private static void Mulyiplication(char[] s1, int len1, char[] s2, int len2) {
//两位乘积位数
int size = len1 +len2 +3;
int []result = new int[size];
for(int i = 0;i<size;i++){
result[i] = 0;
}
//逐位相乘
for(int i = 0;i<len2;i++){
for(int j=0;j<len1;j++){
result[i+j] += (int)(s2[i]-'0') * (int)(s1[j]-'0') ;
}
}
for(int i = 0;i<size;i++){
int carry = result[i]/10;
result[i] = result[i]%10;
if(carry>0)
result[i+1] += carry;
}
int i;
for( i = size-1;i>=0;i--){
if(result[i] > 0)
break;
}
for(int j = 0;j<=i;j++){
System.out.print(result[i-j]);
}
}
/**
* 字符数组倒置
* @param len 数组长度
* @param s 需要倒置的数组
*/
private static void Change(int len, char[] s) {
//高低位对调
for(int i = 0;i<len/2;i++){
s[i] += s[len - 1 - i];
s[len - 1 - i] = (char)(s[i] - s[len - 1 - i]);
s[i] = (char)(s[i] - s[len - 1 - i]);
}
}
}