John Fraser Computer Contest Club

Forums

Post Reply
Forum Home > Java > Yeees,solved an easy problem,lol.

DOM
Member
Posts: 11

DWITE Online Computer Programming Contest October 2009 Problem 4 My First True Letter There are a lot of letters that come and go, but it's those unique letters that really stand out. And not just any unique letter, but the very first one of such. This is what we want to find in a word.

The input file DATA4.txt will contain 5 lines, each a single word of capital letters, at least 1 and no more than 255 characters long.

The output file OUT4.txt will contain 5 lines, each a single letter -- the first letter (left-most) from a word, that is unique to that word.

It is guaranteed for such letter to exist.

Sample Input (first 3 of 5 shown): ABC

ABCA

ABCAB

Sample Output (first 3 of 5 shown): A

B

C



October 23, 2010 at 11:44 AM Flag Quote & Reply

DOM
Member
Posts: 11

now, here goes my code

October 23, 2010 at 11:44 AM Flag Quote & Reply

DOM
Member
Posts: 11

 

import java.io.*;

public class trueLetter {

 

    public static void main (String[] args) throws Exception{

        BufferedReader in=new BufferedReader(new FileReader("in.txt"));

        PrintWriter out=new PrintWriter(new FileWriter("out.txt"));

 

        String input[]=new String[5];

        char output[]=new char[5];

 

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

            input[i]=in.readLine();

        }

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

            output[i]=getChar(input[i]);

            for(int I=0;I<input.length;I++){

                input[I]=input[I].replace(output[i],'$');

            }

            System.out.println (output[i]);

 

        }

}

    public static char getChar(String input){

        char temperate;

        int I=0;

        while((temperate=input.charAt(I))=='$'){

            I+=1;

        }

        return temperate;

 

    }

 

 

}


October 23, 2010 at 11:45 AM Flag Quote & Reply

Rui Lin
Moderator
Posts: 8

Hmm, good try, but I think you misread the question.

It wants the first letter in each word that is unique, ie there is only one occurence of that letter within the word. Each 5 cases are seperate and distinct. The dwite website actually has the test cases they used for past contest questions, so you can try those and see if your program runs right


But you seem to have a good grasp of java. Just note that for dwite, you have to print to the out file, so instead of

System.out.println (output[i]);

use

out.println (output[i]);


at the end of your code, you have to either flush the stream, or close the stream for the data to be actually written to the file. so just

out.close();


at the end would be fine.


October 23, 2010 at 4:16 PM Flag Quote & Reply

DOM
Member
Posts: 11

oooh,right.lol

October 24, 2010 at 11:22 AM Flag Quote & Reply

You must login to post.