| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:1001题,我已经测试了好多数据,在自己机器上都是对的,怎么提交上去都是Runtime Error?In Reply To:1001题,我已经测试了好多数据,在自己机器上都是对的,怎么提交上去都是Runtime Error? Posted by:shuaiwhu at 2011-03-05 16:27:08 > import java.util.Scanner;
>
> class BigNumber {
> private final int LENGTH = 200;
> private int[] integer = new int[LENGTH];
> private int[] decimal = new int[LENGTH];
> private int exp;
>
> public BigNumber(String input) {
> String[] s = input.split(" ");
> exp = Integer.parseInt(s[1]);
> String[] str = s[0].split("\\.");
> if (str.length == 2) {
> for (int i = 0; i < str[0].length(); i++) {
> integer[LENGTH - str[0].length() + i] = str[0].charAt(i) - '0';
> }
> for (int i = 0; i < str[1].length(); i++) {
> decimal[i] = str[1].charAt(i) - '0';
> }
> } else if (str.length == 1) {
> for (int i = 0; i < str[0].length(); i++) {
> integer[LENGTH - str[0].length() + i] = str[0].charAt(i) - '0';
> }
> } else if (str.length > 2) {
> System.out.println("Not a correct number");
> }
> }
>
> public BigNumber(int[] integer, int[] decimal) {
> this.integer = integer;
> this.decimal = decimal;
> }
>
> public int getIntegetBitAtIndex(int i) {
> return integer[i];
> }
>
> public int getDecimalBitAtIndex(int i) {
> return decimal[i];
> }
>
> public void pow() {
> int[] tempInteger = getInteger();
> int[] tempDecimal = getDecimal();
>
> if (this.exp == 0) {
> for (int i = 0; i < LENGTH; i++) {
> integer[i] = 0;
> decimal[i] = 0;
> }
> integer[(LENGTH - 1)] = 1;
> }
> for (int i = 0; i < this.exp - 1; i++) {
> int[] resultInteger = new int[LENGTH];
> int[] resultDecimal = new int[LENGTH];
> for (int j = 0; j < integer.length; j++) {
> if (integer[j] != 0) {
> for (int k = 0; k < tempInteger.length; k++) {
> if (tempInteger[k] != 0)
> resultInteger[j - (LENGTH - 1) + k] += integer[j]
> * tempInteger[k];
> }
> for (int m = 0; m < tempDecimal.length; m++) {
> if (tempDecimal[m] != 0)
> if (j + m - (LENGTH - 1) >= 0) {
> resultDecimal[j + m - (LENGTH - 1)] += integer[j]
> * tempDecimal[m];
> } else {
> resultInteger[j + m + 1] += integer[j]
> * tempDecimal[m];
> }
> }
> }
> }
>
> for (int j = 0; j < decimal.length; j++) {
> if (decimal[j] != 0) {
> for (int k = 0; k < tempInteger.length; k++) {
> if (tempInteger[k] != 0)
> if (j + k - (LENGTH - 1) >= 0) {
> resultDecimal[j + k - (LENGTH - 1)] += decimal[j]
> * tempInteger[k];
> } else {
> resultInteger[j + k + 1] += decimal[j]
> * tempInteger[k];
> }
> }
> for (int m = 0; m < tempDecimal.length; m++)
> if (tempDecimal[m] != 0)
> resultDecimal[m + j + 1] += decimal[j]
> * tempDecimal[m];
> }
> }
>
> for (int j = (LENGTH - 1); j >= 1; j--) {
> if (resultDecimal[j] != 0) {
> int temp = resultDecimal[j];
> resultDecimal[j] = resultDecimal[j] % 10;
> resultDecimal[j - 1] += previousBit(temp);
> }
> }
> if (resultDecimal[0] != 0) {
> int temp = resultDecimal[0];
> resultDecimal[0] = resultDecimal[0] % 10;
> resultInteger[(LENGTH - 1)] += temp / 10;
> }
>
> for (int j = (LENGTH - 1); j >= 0; j--) {
> if (resultInteger[j] != 0) {
> int temp = resultInteger[j];
> resultInteger[j] = temp % 10;
> resultInteger[j - 1] += temp / 10;
> }
> }
> integer = resultInteger;
> decimal = resultDecimal;
>
> }
>
> }
>
> public int[] getInteger() {
> return integer;
> }
>
> public int[] getDecimal() {
> return decimal;
> }
>
> private int previousBit(int bit) {
> if (bit < 10)
> return 0;
> else
> return bit / 10;
> }
>
> public void print() {
> boolean flag = false;
> for (int i = 0; i < LENGTH; i++) {
> if (integer[i] == 0 && !flag)
> continue;
> if (integer[i] != 0) {
> flag = true;
> }
> System.out.print(integer[i]);
> }
>
> boolean outputDot = false;
> int temp = -1;
> for (int j = (LENGTH - 1); j >= 0; j--) {
> if (decimal[j] != 0) {
> temp = j;
> outputDot = true;
> break;
> }
> }
> if (outputDot)
> System.out.print(".");
>
> for (int i = 0; i <= temp; i++)
> System.out.print(decimal[i]);
>
> if(!flag && temp==-1)
> System.out.print(0);
>
> System.out.println();
> }
>
> public int getExp() {
> return exp;
> }
> }
>
> public class Main {
> public static void main(String[] args) {
> Scanner scanner = new Scanner(System.in);
> String str;
> while (scanner.hasNextLine()) {
> str = scanner.nextLine();
> BigNumber bn = new BigNumber(str);
> bn.pow();
> bn.print();
> }
> }
> }
> 我在网上搜到了一个测试数据的input.txt,然后和output.txt对比了的,一摸一样,但就是提交上去有runtime error.
> 希望大家帮我看看。
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator