Category «Conditions: if, then, else»

White pawn move

White pawn move. A white chess pawn moves vertically upwards one square at a time. However, if the pawn is on row #2, it has the option to move either one or two squares upwards. Additionally, a white chess pawn can capture an opponent’s piece by moving diagonally upwards one square to the left or right. …

Vertices of rectangle

Vertices of rectangle. Given integer coordinates of three vertices of a rectangle whose sides are parallel to the coordinate axes, find the coordinates of the fourth vertex of the rectangle. In the first test the three given vertices are (1, 4), (1, 6), (7, 4). The fourth vertex is thus (7, 6). Input Correct answer …

Linear equation

Linear equation. Write a program that solves a linear equation ax = b in integers. Given two integers a and b (a may be zero), print a single integer root if it exists and print “no solution” or “many solutions” otherwise. Input Output 1 -2 -2 2 -1 no solution 5 15 3 -5 30 -6 -7 -7 1  

Next day

Next day. Given the month (an integer from 1 to 12) and the day in it (an integer from 1 to 31) in the year 2017 (or in any other common year), print the month and the day of the next day to it. The first test corresponds to March 30 and March 31. The …

Leap year

Leap year. Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON. The rules in Gregorian calendar are as follows: a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100 a year is …

Chocolate bar

Chocolate bar. Chocolate bar has the form of a rectangle divided into n×m?×? portions. Chocolate bar can be split into two rectangular parts by breaking it along a selected straight line on its pattern. Determine whether it is possible to split it so that one of the parts will have exactly k squares. The program reads three …

Knight move

Knight move. Chess knight moves like the letter L. It can move two cells horizontally and one cell vertically, or two cells vertically and one cells horizontally. Given two different cells of the chessboard, determine whether a knight can go from the first cell to the second in one move. The program receives the input …