PHP Bonus - Online Judge Problem Solving Using PHP
Categories - PHP Tags - PHP   Maniruzzaman Akash   4 months ago   236   0

PHP Bonus - Online Judge Problem Solving Using PHP

Problem Solving

Todays, lecture is totally different from PHP programming language aspects. This is for both PHP and all general level programming languages. Problem Solving is a very important parts to becoming a very good Developer. In our practical life, we’ll face lots of different and new problems every day when we starts our real project. If we have proper problem solving skills, then we can easily solve any problem easily. Let’s try solving some of the problems in popular online judge programming platform.

Popular online problem solving platforms -

  1. BeeCrowd -
  2. UVA Online Judge -
  3. HackerRank Online Judge -
  4. CodeForce Online Judge -
  5. LightOJ -

And there is so many online programming problem solving websites out there. We’ll start using the easiest one BeeCrowd or previously URI online judge.

BeeCrowd Online Judge

BeeCrowd is one of the most popular online judge problem solving platform. It’s suitable for both beginner, intermediate and advanced level users.

How we’ll solve the problems ?

We’ll read the problems very carefully and solve those problems using PHP language. You can try with other language also if you’re comfortable. We’ll solve some Beginner Level problems -

Test in Online PHP Code -

Problem 1: Hello World

Problem Details

beecrowd | 1000

Hello World!

Jean Bez, beecrowd Brasil

Timelimit: 1

Welcome to beecrowd!

Your first program in any programming language is usually "Hello World!". In this first problem all you have to do is print this message on the screen.


This problem has no input.


You must print the message Hello World! and then the endline as shown below.

Input Sample Output Sample

Hello World!

Solution in PHP


echo "Hello World!\n";


Problem 2: Extremely Basic

Solution in PHP


$input1 = intval(fgets(STDIN));
$input2 = intval(fgets(STDIN));
$summation = $input1 + $input2;

echo "X = $summation\n";


Problem 3 - Multiples

Solution in PHP


$numbers = fgets(STDIN);

$a = intval(explode(" ", $numbers)[0]);
$b = intval(explode(" ", $numbers)[1]);

if (($b % $a == 0) || ($a % $b == 0)) {
    echo "Sao Multiplos\n";
} else {
    echo "Nao sao Multiplos\n";


Problem 4 - Upto Odd Numbers

Solution in PHP


$x = intval(fgets(STDIN));

for($i = 1; $i <= $x; $i += 2) {
    echo $i . "\n";

PHP Array Part 2 - Array Built in PHP Functions and Some More Examples
PHP - Functions in PHP - How to create and how to use