You all are welcomed again to my blog. This is my first post, first step and first attempt to take you all to the ground floor of coding, from a newbie to a learning beginner.
In this post we will learn some basic information of competitive coding and how to attempt the given questions using c++. Though you can try in any other programming language other than C++.
Prerequisites: Basic concepts/Syntax of any programming language (C, C++, Java, Python, Kotlin etc).
* Start Learning*
Here are the brief details of some of the terms we will cross across throughout the learning.
1) Input/Output :: ‘Input’ is information supplied to a computer or program. ‘Output’ is the information provided by a computer or program.
2) Constraints :: Constraints are the set of valid input data. No input data will be more or less than the given constraints limit of the question.
3) Time Limit :: The time limit applies to the sum of the compilation time and the running time.
If your code takes more time than the given limit, the code will not be processed further and will show an error i.e, Time Limit Exceed (tle) and you will not be able to know if your code gives correct solution or not.
Let’s understand all these by an real example.
And here we are with our first example question FLOW001 from codechef .
Example =>
°Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.
Program is very simple, Given two integers A and B, write a program to add these two numbers
Input:
The first line contains two Integers A and B.
Output:
Add A and B and display it.
Constraints:
1 ≤ A,B ≤ 10000
Example
Input
1 2
100 200
10 40
Example
Output:
3
300
50
Explanation of the question :
In this example, we have to take input two no A and B. We have to add A and B and print the output.
Be careful while taking input or output data. We have to take input data in the exact way as the question is demanding.
Again, for example :: you can’t take input like “Enter two numbers”. See in the example input we only have to take input two single numbers 1 and 2 or 100 and 200 or 10 and 40.
In c++ you can take these input simply as
Cin>>A>>B;
§imilarly, you can’t print output as
THE SUM IS :: 3
You just have to print a single no 3 (sum of A and B) in the output.
Cout<<A+B;
The input A and B will not be less than 1 or more than 1000 according to the constraints.
You should first try this question on your own in any programming language you are comfortable with before moving ahead.
**** I really hope you all have tried on your own first****
#include<iostream.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
° §ee, so simple solution, isn’t it?
After having rough idea about competitive coding . I guess you all are ready with me to enhance your skills by practising more and more coding questions.
And for that,
§tay tuned for my next post and for our next challenge.
I hope you all are doing fine.