반응형

1. 디렉토리 구조

ProgrammingChallenges

  - classes

  - datafiles

     - id110101

        - The3nPlus1-in

        - The3nPlus1-out

  - src

     - id110101

        - The3nPlus1.java


  test.bat


2. test.bat

@echo off


set PACKAGE_NAME=id110101

set PROGRAM_NAME=The3nPlus1



set OUTPUT_DIR=classes

set DATA_DIR=datafiles


javac -d %OUTPUT_DIR% src/%PACKAGE_NAME%/%PROGRAM_NAME%.java

cd %OUTPUT_DIR%

java -cp . %PACKAGE_NAME%.%PROGRAM_NAME% < ../%DATA_DIR%/%PACKAGE_NAME%/%PROGRAM_NAME%-in > out


@echo on

fc out ../%DATA_DIR%/%PACKAGE_NAME%/%PROGRAM_NAME%-out


@echo off

cd ..


3. 기본 입출력 틀

package id110101;


/* @BEGIN_OF_SOURCE_CODE */


/* @JUDGE_ID: 75154 100 Java "" */


import java.io.*;

import java.util.*;


public class The3nPlus1 {

public static void main(String[] args) {

The3nPlus1 main = new The3nPlus1();

main.begin();


}

private void begin() {

String line;

StringTokenizer st;

long first, second;

while ((line = readLine(255)) != null && !line.isEmpty()) {

st = new StringTokenizer(line);

first = Long.parseLong(st.nextToken());

second = Long.parseLong(st.nextToken());

System.out.println(String.format("%d %d", first, second));

}

}

private static String readLine(int maxLg) {

byte lin[] = new byte[maxLg];

int lg = 0;

int car = -1;

String line = "";

try {

while (lg < maxLg) {

car = System.in.read();

// 10: Line feed   13: Carriage return

if ((car < 0) || (car == 10) ) {

break;

}

lin[lg++] += car;

}

} catch (IOException e) {

return null;

}

if ((car < 0) && (lg == 0)) return null;

line = new String(lin, 0, lg);

line = line.replaceAll("[\n\r]", "");

return line;

}


}


/* @END_OF_SOURCE_CODE */















반응형
Posted by seungkyua@gmail.com
,