#6266: 為什麼會TLE?


cs2012 (小嫩咖)

學校 : 國立臺中第一高級中學
編號 : 23521
來源 : [61.216.15.113]
最後登入時間 :
2012-02-14 00:48:25

以下是我的code

很疑惑說,為什麼這種做會TLE?

 

import java.io.*;
import java.util.Scanner;

public class Practice
{
    public static void main(String[] args)throws IOException
    {
        Scanner in=new Scanner(System.in);
        int t;
       
        while(in.hasNext())
        {
            t=in.nextInt();
           
            for(int i=0;i<t;i++)
            {
                int product=1;
                int test;
                test=in.nextInt();
                int j=System.in.read();
                boolean exist_0=false;
                while(j != 10)
                {
                    if(j>='1' && j<='9' && exist_0 == false)
                        product*=(j-'0');
                    else if(j == '0')
                        exist_0=true;
                    j=System.in.read();
                       
                }
               
                if(exist_0)
                    System.out.println(0);
                else
                    System.out.println(product);
               
            }
        }
    }
}