Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum


somebody tellme what is my wrong ty -- Problem 1060

Kyoo 8119. somebody tellme what is my wrong ty
2010-07-24 15:32:44 import java.util.*;
import java.io.*;
import java.math.*;
public class ProblemC {
    static int n;
    public static void resolver(String t){
        StringTokenizer s=new StringTokenizer(t,"[+|-|*]",true);
        BigInteger a=new BigInteger(s.nextToken());
        String tipo=s.nextToken();
        BigInteger b=new BigInteger(s.nextToken());
        if(tipo.equals("+"))
            suma(a,b);
        else if(tipo.equals("-"))
            resta(a,b);
        else
            multip(a,b);
        System.out.println();
    }
    public static void suma(BigInteger a,BigInteger b){
        String txtA=a.toString(),txtB=b.toString(),txtRes=a.add(b).toString();
        int tamMax=Math.max(txtA.length(),txtB.length()+1);

        System.out.println(espacios(tamMax-txtA.length())+txtA);
        System.out.println(espacios(tamMax-txtB.length()-1)+"+"+txtB);
        System.out.println(guiones(tamMax));
        System.out.println(espacios(tamMax-txtRes.length())+txtRes);
    }
    public static void resta(BigInteger a,BigInteger b){
        String txtA=a.toString(),txtB=b.toString(),txtRes=a.subtract(b).toString();
        int tamMax=Math.max(txtA.length(),txtB.length()+1);
        System.out.println(espacios(tamMax-txtA.length())+txtA);
        System.out.println(espacios(tamMax-txtB.length()-1)+"-"+txtB);
        System.out.println(guiones(tamMax));
        System.out.println(espacios(tamMax-txtRes.length())+txtRes);
    }
    public static void multip(BigInteger a,BigInteger b){
        String txtA=a.toString(),txtB=b.toString(),txtRes=a.multiply(b).toString();
        int tamMax1=Math.max(txtA.length(),txtB.length()+1);
        int tamMax2=Math.max(tamMax1,txtRes.length());

        System.out.println(espacios(tamMax2-txtA.length())+txtA);
        System.out.println(espacios(tamMax2-txtB.length()-1)+"*"+txtB);
        System.out.println(espacios(tamMax2-tamMax1)+guiones(tamMax1));
        if(txtB.length()>1){
            for(int i=0,c=txtB.length()-1;i<txtB.length();i++,c--){
                BigInteger valP=new BigInteger(txtB.charAt(c)+"");
                String txtResP=valP.multiply(a).toString();
                System.out.println(espacios(tamMax2-txtResP.length()-i)+txtResP);
            }
            System.out.println(guiones(tamMax2));
        }
        System.out.println(espacios(tamMax2-txtRes.length())+txtRes);
    }
    public static String espacios(int n){
        String espacios="";
        for (int i = 0; i <n; i++) espacios+=" ";
        return espacios;
    }
    public static String guiones(int n){
        String guiones="";
        for (int i = 0; i <n; i++) guiones+="-";
        return guiones;
    }
    public static void main(String[] args) throws IOException{
        Scanner leer = new Scanner(System.in);
        n= leer.nextInt();
        for(int i=1;i<=n;i++)
            resolver(leer.next());
    }
}
  1

Search    Goto Page:  
User ID:
Password:
Title:   Forum Tag

Tianjin University Online Judge v1.2.4