-
-
Notifications
You must be signed in to change notification settings - Fork 6
Example: How to solve a problem using Kat CLI (C#)
This is a guide on how you would go about solving a Kattis problem using this repository's Kat CLI.
We will be using the 3 most simple commands, get
, test
and submit
, and this will be performed on a Windows 10 computer with Visual Studio Code as my chosen editor. You can change the language to be anything you want, but for this example i am using C#
.
Starting off, you find a problem on the Kattis problems website, and for simplicity's sake, a non-interactive problem (meaning we will get a simple input and will have to output something simple as well).
For this example i have chosen I've Been Everywhere, Man and the problemname
for this one is everywhere
. This is the URL name, which we will need for the commands.
I have a folder on my computer called Kattis and this is where i want all my Kattis solves and problems to be located. Since this is a CLI (Command Line Interface), i will open a cmd.exe
console in this location.
If you have set up the Kat CLI properly, we can call the Kattis
commands in all folders. As we now have the location for our code and the problem we want to solve, we can start with Kattis get everywhere
. Depending on the language, this will run a number of different commands.
For C#
this will first off create a new folder with the same name as the problem. My folder is now Kattis\everywhere
, and it will then run dotnet new console
which creates a C# project
and a Program.cs
file for this project which is where we will write the code to solve the problem.
Inside Program.cs
you will write the solution to the Kattis problem. For this problem we will be reading some integers and having a Set
of which unique cities that have been visited.
Code is as follows (C#):
using System;
using System.Collections.Generic;
namespace everywhere
{
class Program
{
static void Main(string[] args)
{
int T = Int32.Parse(Console.ReadLine());
for(int t = 0; t < T; t++){
int n = Int32.Parse(Console.ReadLine());
HashSet<string> cities = new HashSet<string>();
for(int i = 0; i < n; i++){
cities.Add(Console.ReadLine());
}
Console.WriteLine(cities.Count);
}
}
}
}
I have now written my code and i want to test it against the small samples of tests that is provided, before i upload it to Kattis. We can use the Kattis test
command to do this.
In the same console that we have open in the Kattis
folder, we test the solve to the problem with Kattis test everywhere
. This will either fail or pass, and it even gives errors if the code doesn't compile.
If the test passes, it will show like this:
π Running tests on Program.cs
dotnet None
run None
π everywhere/test/everywhere-01.in succeeded
Important: Sometimes the test will fail, but the input looks correct, this is due to white-space errors or even rounding/floating point amount. These may still get accepted on the Kattis website.
Now that we know our code works on the test samples, we can submit it to the Kattis website. We do this with the command Kattis submit
. And we need to submit the correct problem code here, it will find the correct file if we write Kattis submit everywhere
. You will get prompted if you want to submit this code:
Are you sure you want to submit?
Problem: everywhere
File: everywhere\Program.cs
Language: C#
(y/N):
At this point we type y
and press enter
. The file will be uploaded to the Kattis server and tested against the problem. In the console we will see the current submission status and even get the URL to check it out in a web browser.
The code either gets accepted or declined (for a number of reasons), this exact example here we have an accepted submission:
π¨ Submitting everywhere...
π¬ Submission Successful (url https://open.kattis.com/submissions/xxxxxxx)
βοΈ Submission Status:
ππ
π Congratulations! You completed all 2 tests for everywhere
With this workflow, you can rinse and repeat without having to open a new console and only have to find new problems on the website when you solve a problem.
Enjoy solving Kattis problems with Kat CLI!