uva oj java输入输出

 

/**
 * ### 真難的題目: 狗屁演算法 (測資很機車)
 * 測驗結果: x.xx0 ms
 * 測驗日期: 200y-mm-dd
 * @author Raymond Wu (小璋丸)
 */
public class Main {
 
  // 輸入緩衝區 (緩衝空間需要依照題目調整)
  public static byte[] cinbuf = new byte[1024];
 
  // 讀取一個單字 (英文姓名包含空白時請不要用)
  public static String readToken() {
    int offset = 0;
    int bytedata = -1;
    
    try {
      // 略過非單字的字元 '/t','/n','/r',' '
      bytedata = System.in.read();
      while(bytedata==9||bytedata==10||bytedata==13||bytedata==32) {
        bytedata = System.in.read();
      }
 
      // 載入單字的字元
      while(bytedata!=-1) {
        if(bytedata==9||bytedata==10||bytedata==13||bytedata==32) {
          break;
        } else {
          cinbuf[offset++] = (byte)bytedata;
        }
        bytedata = System.in.read();
      }
    } catch(Exception e) {}
    
    if(offset+bytedata==-1) return null; // 串流結束
    return new String(cinbuf,0,offset);
  }
  
  // 讀取一行
  public static String readLine() {
    int offset = 0;
    int bytedata = -1;
    
    try {
      // 載入整行
      bytedata = System.in.read();
      while(bytedata!=-1) {
        if(bytedata==10) {
          break;
        } else {
          cinbuf[offset++] = (byte)bytedata;
        }
        bytedata = System.in.read();
      }
    } catch(Exception e) {}
 
    if(offset+bytedata==-1) return null; // 串流結束
    if(cinbuf[offset-1]=='/r') offset--; // window 要去除 '/r' 字元
    return new String(cinbuf,0,offset);
  }
  
  // 轉成 int 型態 (比 Integer.parseInt() 快)
  public static int parseInt(String s) {
    int i;
    int mul = 10;
    int value = s.charAt(s.length()-1)-48;
    
    for(i=s.length()-2;i>=0;i--) {
      value += (s.charAt(i)-48)*mul;
      mul *= 10;
    }
    
    return value;
  }
  
  public static void main(String[] args) {
    // TODO
  }
 
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值