hdu 3546

          大數相加,一個很簡單的程序。用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]);
		}
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章