Skip to content

This repository contains a Java program designed for competitive programming. It provides a basic structure for efficiently handling input and output .

Notifications You must be signed in to change notification settings

debapriyo007/Taking-IO-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

Competitive Programming I/O In Java

This repository contains a Java program designed for competitive programming. It provides a basic structure for efficiently handling input and output using custom classes (InputReader and OutputWriter) to streamline the problem-solving process during contests.

Table of Contents

Coding Platform Accepted
CodeChef ✅ Yes
Codeforces ✅ Yes

Features

  • Custom Input Handling:

    • InputReader supports efficient reading of various data types such as int, long, double, and strings.
    • Supports reading lines for custom input scenarios.
  • Custom Output Handling:

    • OutputWriter enables fast and efficient output.
    • Provides methods to write and writeLine for better control over the output.
  • Error Handling:

    • Includes runtime exception handling for input/output operations.

Usage

  • Copy the bellow code and use it for competitive programming.
  • Accepted in any competitive programming platform.

Boilerplate Code

import java.util.*;
import java.io.*;

public class CompetitiveProgrammingSolution {

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException("Error reading input", e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String readLine() {
            String inputLine = "";
            try {
                inputLine = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException("Error reading line", e);
            }
            return inputLine;
        }
    }

    static class OutputWriter {
        private BufferedWriter writer;

        public OutputWriter() {
            writer = new BufferedWriter(new OutputStreamWriter(System.out));
        }

        public void write(Object object) throws IOException {
            writer.write(object.toString());
        }

        public void writeLine(Object object) throws IOException {
            write(object);
            writer.newLine();
        }

        public void close() throws IOException {
            writer.close();
        }
    }

    public static void main(String[] args) {
        try {
            InputReader inputReader = new InputReader();
            OutputWriter outputWriter = new OutputWriter();

            int T = inputReader.nextInt();
            while (T -- > 0) {
               
               // Solve the problem here
               // Call the solveProblem method.
            }
            outputWriter.close();
        } catch (Exception e) {
            System.err.println("Error during program execution: " + e.getMessage());
        }
    }

}
  1. InputReader: Handles reading input from the standard input.
  2. OutputWriter: Handles writing output to the standard output.
  3. solveProblem: The main logic for solving the competitive programming problem goes here.

Acknowledgments

  • Java community for the efficient BufferedReader and BufferedWriter classes.
  • Inspiration from competitive programming contests such as Codeforces, LeetCode, and HackerRank.

alt text

About

This repository contains a Java program designed for competitive programming. It provides a basic structure for efficiently handling input and output .

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published