文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>hdu 3546(高精度,java写)...

hdu 3546(高精度,java写)...

时间:2010-08-18  来源:xiaotaoqibao

Calculator

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 173    Accepted Submission(s): 65

Problem Description Golden Adobe is the most advanced computer for scientific computing in the world. Unfortunately, it broke down. Your task is to write a super computing software to take its place. The software contains 10 registers named from A to J. There are three operations on the registers:
1) Assignment: X=Y
2) Addition: X+=Y
3) Multiplication: X*=Y
Notice that X and Y are two registers, and they may be the same.
Initially, all the registers are stored by integer 1. Your program should operate several operations and output the final result for 10 registers. You may assume that the length of each decimal number stored in the register is no longer than 5000.
  Input The input contains only one test case including several lines.
Each line contains an operation to be calculated.
The number of operations will no more than 300000.
  Output The output should contains exactly 10 lines, each line contains an integer denoting the decimal number in the register. See sample test case for further details.   Sample Input
A+=B
A*=A
A+=A
B+=A
C+=B
D=B
  Sample Output
8
9
10
9
1
1
1
1
1
1import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin=new Scanner(System.in);
        BigInteger elem[] = new BigInteger[10];
        String str;
        int i,j;
        for(i=0;i<10;i++)
            elem[i] = BigInteger.ONE;
        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']);
            }
        }
        for(i=0;i<10;i++)
        {
            System.out.println(elem[i]);
        }
    }

}
 
相关阅读 更多 +
排行榜 更多 +
我的时装店无限金币版

我的时装店无限金币版

休闲益智 下载
星厨烹饪记内置MOD菜单

星厨烹饪记内置MOD菜单

模拟经营 下载
勇士食堂MOD内置菜单

勇士食堂MOD内置菜单

模拟经营 下载