Skip to content

Instantly share code, notes, and snippets.

@siketyan
Created March 24, 2019 14:13
Show Gist options
  • Save siketyan/6e01467e9a33622cc6423bb127da3391 to your computer and use it in GitHub Desktop.
Save siketyan/6e01467e9a33622cc6423bb127da3391 to your computer and use it in GitHub Desktop.
Competitive Programming Template
using System;
using System.Collections.Generic;
using System.Linq;
namespace Contest
{
internal class Problem
{
public static void Main()
{
// Solve
}
#region Input and Output
private static readonly List<string> _buffer = new List<string>();
private static string Cin()
{
ReadBuffer();
var str = _buffer.First();
_buffer.RemoveAt(0);
return str;
}
private static IEnumerable<string> CinA() => Console.ReadLine()?.Split();
private static int Cint() => int.Parse(Cin());
private static int[] CintA() => CinA().Select(int.Parse).ToArray();
private static void Cout(object obj) => Console.WriteLine(obj);
private static void ReadBuffer()
{
if (_buffer.Any()) return;
var line = Console.ReadLine();
if (line.Contains(' '))
{
_buffer.AddRange(line.Split());
}
else
{
_buffer.Add(line);
}
}
#endregion
#region Loops
private static void Loop(int count, Action<int> action) => Loop(0, count, action);
private static void Loop(int init, int count, Action<int> action, int step = 1)
{
for (var i = init; i < count + init; i += step)
{
action(i);
}
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment