各种各样的输入输出挂 mmdns~
来源:互联网 发布:生态监测网络建设方案 编辑:程序博客网 时间:2024/06/06 00:16
原链接:点击打开链接
先上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
- 各种各样的输入输出挂 mmdns~
- 各种各样的游戏,各种各样的人
- 各种各样的面试问题
- 各种各样的线条
- 各种各样的面试问题
- 各种各样的计算机视频
- 各种各样的“人品”
- 各种各样的飞鸽传书
- 各种各样的按钮
- 各种各样的正则表达式
- 各种各样的api查询
- 各种各样的树
- 各种各样的鼠标行政
- 各种各样的Slider
- 各种各样的文章
- 各种各样的 编程练习
- 各种各样的api查询
- 各种各样有用的网站
- Maven的安装、配置及使用
- 【函数】复数计算
- SEO——网站搜索引擎优化
- Ruby on Rails微信开发1——开发模式的启用与接口配置
- JVM-运行时数据区
- 各种各样的输入输出挂 mmdns~
- yuanchuangwenagcfdecf
- Cracking the coding interview--Q8.4
- 自然图片文字提取
- weiyi通讯录(四)获取通话记录
- 排序有哪几种好方法(仅供参考)
- STM32.ADC
- JAVA进程内存用量高的分析与解决
- Android 数据库进阶之事务处理批量数据