大数相加,一个很简单的程序。用java解决就很简单了啊!
package hdu;
import java.math.BigInteger;
import java.util.Scanner;
public class Main3546 {
public static void main(String[] args){
Scanner cin = new Scanner(System.in);
BigInteger[] elem = new BigInteger[10];
for(int i=0; i<elem.length; i++){
elem[i] = BigInteger.ONE;
}
String str;
// int count = 0;
while(cin.hasNext()){
str = cin.next();
if(str.length() == 3){
elem[str.charAt(0)-'A']= elem[str.charAt(2)-'A'];
}else{
if(str.charAt(1)== '+')
elem[str.charAt(0)-'A'] = elem[str.charAt(0)-'A'].add(elem[str.charAt(3)-'A']);
else
elem[str.charAt(0)-'A'] = elem[str.charAt(0)-'A'].multiply(elem[str.charAt(3)-'A']);
}
// count++;
// if(count==6)break;
}
for(int i=0; i<elem.length; i++){
System.out.println(elem[i]);
}
}
}