https://github.com/debapriyo007/taking-io-java
This repository contains a Java program designed for competitive programming. It provides a basic structure for efficiently handling input and output .
https://github.com/debapriyo007/taking-io-java
boilerplate-template bufferreader cp io java
Last synced: 9 months ago
JSON representation
This repository contains a Java program designed for competitive programming. It provides a basic structure for efficiently handling input and output .
- Host: GitHub
- URL: https://github.com/debapriyo007/taking-io-java
- Owner: debapriyo007
- Created: 2025-01-26T14:41:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-01-26T15:35:20.000Z (11 months ago)
- Last Synced: 2025-01-26T16:27:31.333Z (11 months ago)
- Topics: boilerplate-template, bufferreader, cp, io, java
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 |
|---------------------------------------------------------------------------------------------|-----------------|
|  | ✅ Yes |
|  | ✅ 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
```java
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.