Skip to content

Instantly share code, notes, and snippets.

@kuuso
Created February 7, 2015 18:23
Show Gist options
  • Save kuuso/ec0df4770466bda519c9 to your computer and use it in GitHub Desktop.
Save kuuso/ec0df4770466bda519c9 to your computer and use it in GitHub Desktop.
デカい入力用
using System;
using System.Text;
using System.IO;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
//using内で使う方が安全か。
//リダイレクトで渡さないと止まる。。。
using(FastIn rd = new FastIn()){
Console.WriteLine(rd.ReadInt());
Console.WriteLine(rd.ReadStr());
}
}
public Sol(){
}
}
class FastIn:IDisposable {
int Size;
byte[] Mem;
int ptr;
int rsize;
bool unfinished;
Stream stdin;
void Init(int n) {
Size = n;
Mem = new byte[Size];
rsize=(stdin=Console.OpenStandardInput()).Read(Mem, 0, Size);
ptr = 0;
unfinished=(rsize == Size);
}
void Next() {
if (unfinished == false) return;
rsize=stdin.Read(Mem, 0, Size);
ptr = 0;
unfinished = (rsize == Size);
}
~FastIn(){
stdin.Dispose();
}
void IDisposable.Dispose(){
stdin.Dispose();
}
public void Dispose(){
stdin.Dispose();
}
public FastIn() {
Init(1000000);
}
public FastIn(int n) {
Init(n);
}
public int ReadInt() {
int ret = 0;
int sig = 1;
while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
if(ret==0 && Mem[ptr] == '-'){
sig *= -1; ptr++; continue;
}
ret = ret * 10 + Mem[ptr++] - '0';
if (ptr == Size) Next();
}
while (ptr < rsize && (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r') ) {
ptr++;
if (ptr == Size) Next();
}
return ret*sig;
}
public long ReadLong() {
long ret = 0;
long sig = 1;
while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r' ) {
if(ret==0 && Mem[ptr] == '-'){
sig *= -1; ptr++; continue;
}
ret = ret * 10 + Mem[ptr++] - '0';
if (ptr == Size) Next();
}
while (ptr < rsize && (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r') ) {
ptr++;
if (ptr == Size) Next();
}
return ret*sig;
}
public String ReadStr() {
//2byte文字はNG
StringBuilder sb = new StringBuilder();
while (ptr < rsize && Mem[ptr] != ' ' && Mem[ptr] != '\n' && Mem[ptr] != '\r') {
sb.Append((char)Mem[ptr++]);
if (ptr == Size && unfinished) Next();
}
while (ptr < rsize && (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r') ) {
ptr++;
if (ptr == Size && unfinished) Next();
}
return sb.ToString();
}
public String ReadLine() {
//極力使わない(split/parseするくらいなら上をつかう)
StringBuilder sb = new StringBuilder();
while (ptr < rsize && Mem[ptr] != '\n' && Mem[ptr] != '\r') {
sb.Append((char)Mem[ptr++]);
if (ptr == Size && unfinished) Next();
}
while (ptr < rsize && (Mem[ptr] == ' ' || Mem[ptr] == '\n' || Mem[ptr] == '\r')) {
ptr++;
if (ptr == Size && unfinished) Next();
}
return sb.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment