본문 바로가기
Programming/Contest

Qualification Round Africa 2010 Problem B. Reverse Words 그래도 예선은 통과해보자.

by NAMP 2012. 3. 6.

   

"그래도 예선은 통과해보자" 라는 심정으로 글을 작성합니다.

(이야기 하는 형식으로 적다 보니, 자연스레 높임말이 나오네요)

   

구글 코드 잼 코리아에서 당한 충격으로 자연스레 연습이 필요하다는 생각이 들었습니다.

   

http://code.google.com/codejam/

Registration opens on Tuesday, March 13th, 2012.

   

   

일단, 프랙티스

쉬운것부터 해보기 위해서,

http://code.google.com/codejam/contest/351101/dashboard#s=p1

   

Qualification Round Africa 2010 Problem B. Reverse Words 선택했습니다.

   

작은 입력 파일은 보니

위와 같습니다.

이를 줄 단위 단어 역순으로 표현하면 되겠네요.

   

   

   

   

code

import java.io.*;

   

public class Qualification_Round_Africa_2010_Reverse_Words {

   

/**

* @param args

*/

public static void main(String[] args) {                

String strFileName = "QRA2010_B-large-practice";

String strInputFileName = strFileName + ".in";

String strOutputFileName = strFileName + ".out";

   

int totalNumber = 0;

int outputCaseNumber = 1;

   

try {                 

        ////////////////////////////////////////////////////////////////

        BufferedReader in = new BufferedReader(new FileReader(strInputFileName));

        BufferedWriter out = new BufferedWriter(new FileWriter(strOutputFileName));

        String s;

 

        totalNumber = Integer.parseInt(in.readLine());

          

while ((s = in.readLine()) != null) {

        System.out.println(s);

          

        String[] array;                         

        array = s.split(" ");

          

        String[] reversedWords = new String[array.length];

          

        s = "";

          

        for (int i = 0; i < array.length; i++) {

reversedWords[i] = array[array.length -1 -i];

s = s + reversedWords[i] + " ";

}

          

        s = String.format("Case #%d: %s\n", outputCaseNumber++, s);

        System.out.print(s);

        out.write(s);

}

in.close();

out.close();

////////////////////////////////////////////////////////////////

} catch (IOException e) {

        System.err.println("ERROR");

System.err.println(e); // 에러가 있다면 메시지 출력

System.exit(1);

}

   

}

}

   

다음 문제를 찾아보자.

'Programming > Contest' 카테고리의 다른 글

GCJ_2012_Registration  (0) 2012.03.14
Qualification Round Africa 2010 - Problem C. T9 Spelling  (0) 2012.03.06
코드게이트2012  (0) 2012.02.24
code jam 2012 일정.  (0) 2012.02.23
Registration opens on Tuesday, March 13th, 2012.  (0) 2012.02.20

댓글