A题为什么用StreamTokenizer进行输入获取会错误

//答案错误,说是只对了一半
import java.io.*;
import java.math.BigInteger;
  
  
public class Main
{
    public static void main(String[] args) {
        StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out=new PrintWriter(System.out);
        try {
            in.nextToken();
            int n=(int)in.nval;
            for(int i=0;i<n;i++)
            {
                in.nextToken();
                BigInteger a=BigInteger.valueOf((long) in.nval);
                in.nextToken();
                BigInteger b=BigInteger.valueOf((long) in.nval);
                in.nextToken();
                BigInteger c=BigInteger.valueOf((long) in.nval);
                out.println(a.modPow(b, c));
            }
            out.flush();
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

//ac通过的代码
import java.io.*;
import java.math.BigInteger;
  
publicclassMain
{
    publicstaticvoidmain(String[] args) {
//      StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        Scanner in=newScanner(System.in);
        PrintWriter out=newPrintWriter(System.out);
        intn=in.nextInt();
        BigInteger a,b,c;
        for(inti=0;i<n;i++)
        {
            a=in.nextBigInteger();
            b=in.nextBigInteger();
            c=in.nextBigInteger();
            out.println(a.modPow(b, c));
        }
        out.flush();
        out.close();
    }
}

全部评论
试一下  st.ordinaryChars('0&(30533)#39;, '9&#39;); // 提升long精度问题,大概率是 StreamTokenizer源码处理问题st.wordChars('0&(30533)#39;, '9&#39;); // 提升long精度问题,小概率输入数据多了某种符号 st.nextToken(); return Long.parseLong(st.sval); 替换掉 st.nextToken(); return (long) st.nval;
点赞
送花
回复
分享
发布于 04-27 13:20 广东

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务