各种各样的输入输出挂 mmdns~

原链接:点击打开链接

先上C的:

适用于正int的.

int read(){//输入优化
    char ch = ' ';
    while(ch < '0' || ch > '9') ch = getchar();
    int x = 0;
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}

适用于正负int / LL / double 的. (来自 风神)

template <class T>
bool scan_d(T &ret)
{
    char c;
    int sgn;
    T bit=0.1;
    if(c=getchar(), c==EOF)
        return 0;
    while(c!='-' && c!='.' && (c<'0' || c>'9'))
        c=getchar();
    sgn=(c=='-')? -1:1;
    ret=(c=='-')? 0:(c-'0');
    while(c=getchar(), c>='0' && c<='9')
        ret=ret*10+(c-'0');
    if(c==' ' || c=='\n')
    {
        ret*=sgn;
        return 1;
    }
    while(c=getchar(), c>='0' && c<='9')
        ret+=(c-'0')*bit, bit/=10;
    ret*=sgn;
    return 1;
}

-----------------------------------------------------------------------------------------------------------

然后是 java 的.(根本不会脚哇233)

import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.*;
import java.io.*;
import java.util.*;

class Scanner 
{
    BufferedReader br;
    StringTokenizer st;
    public Scanner(InputStream in) 
    {
        br = new BufferedReader(new InputStreamReader(in));
        eat("");
    }
    private void eat(String s) 
    {
        st = new StringTokenizer(s);
    }
    public String nextLine()
    {
        try
        {
            return br.readLine();
        } 
        catch (IOException e) 
        {
            return null;
        }
    }
    public boolean hasNext() 
    {
        while (!st.hasMoreTokens())
        {
            String s = nextLine();
            if(s == null)
                return false;
            eat(s);
        }
        return true;
    }
    public String next()
    {
        hasNext();
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble() 
    {
    return Double.parseDouble(next());
    }
}

while(in.hasNext()) 是输入到EOF结束

输入BigInteger 要

BigInteger a=new BigInteger(in.next());

前期一直用这个

后来... 发现另一个更短的...  

缓冲输入流

包含了输入输出和输出挂

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
    public static void main(String[] args) throws NumberFormatException, IOException
    {
         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
         PrintWriter out = new PrintWriter(System.out);



        out.close();
    }
}

仅能输入string 或单个字符

如输入 int:

  int t=new Integer(in.readLine());

至今不会如何EOF...

所以, 综上!

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{

    public static void main(String[] args)
    {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        
        
        
        out.close();
    }
}
class InputReader
{
    BufferedReader buf;
    StringTokenizer tok;
    InputReader()
    {
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext()
    {
        while(tok == null || !tok.hasMoreElements()) 
        {
            try
            {
                tok = new StringTokenizer(buf.readLine());
            } 
            catch(Exception e) 
            {
                return false;
            }
        }
        return true;
    }
    String next()
    {
        if(hasNext()) return tok.nextToken();
        return null;
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    BigInteger nextBigInteger()
    {
        return new BigInteger(next());
    }
    BigDecimal nextBigDecimal()
    {
        return new BigDecimal(next());
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值