Automate input parsing for competitive programming problems
# CPInput - Smart Input Parser for Competitive Programming Convert problem statements into clean input parsing code instantly with AI-powered precision or fast regex templates.- Dual Parsing Engine: Choose between ultra-fast regex templates or high-accuracy Gemini AI
- Multi-language Support: Generate input code for Python, C++, Java, and more
- Privacy Focused: Works offline with regex; API calls go directly to Google
- Competitive Programming Optimized: Generates efficient parsing code
- Extensible: Easily add new regex patterns or customize AI prompts
git clone https://github.com/adnantabda/cpinput.git
cd cpinput
npm install
npm run buildDon't Forget to add Your own API KEY
- Open Chrome and navigate to
chrome://extensions - Enable "Developer mode"
- Click "Load unpacked" and select the
distfolder
- Navigate to any competitive programming problem
- Click Generate Input code
| Feature | Regex Parser | Gemini AI |
|---|---|---|
| Accuracy | 65% (common cases) | 95%+ cases |
| Speed | Instant | 1-10 seconds |
| Offline Support | ✅ Yes | ❌ Requires API |
| Best For | Standard inputs | Complex problems |
Add your own patterns to src/templates.js:
{
regex: /contains (\d+) floats? (.*)/i,
code: '$1_floats = list(map(float, input().split())) // $2'
}Modify the system instruction for different behaviors:
const response = await ai.models.generateContent({
model: "gemini-2.0-flash",
contents: `Convert this ${lines} to ${lang} code`,
config: {
systemInstruction: `You are an expert at generating input parsing code.
Return only pure code without comments or explanations.
Use efficient methods suitable for competitive programming.`,
temperature: 0.1,
topP: 0.95,
maxOutputTokens: 512,
},
});Problem Statement:
The first line contains integer T
Each of the next T lines contains two integers
Generated Python:
T = int(input())
for _ in range(T):
a, b = map(int, input().split())Problem Statement:
First line contains R and C
Next R lines contain C space-separated integers
Generated Python:
R, C = map(int, input().split())
matrix = [list(map(int, input().split())) for _ in range(R)]We welcome contributions! Please see our Contribution Guidelines.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
https://github.com/adnantabda/cpinput