0% found this document useful (0 votes)
2 views

#1 DataTypes&Conditions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

#1 DataTypes&Conditions

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

,

Say Hello With C++


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a name S. Print “Hello, (name)” without parentheses.

Input
Only one line containing a string S.

Output
Print “Hello, ” without quotes, then print name.

Example
standard input standard output
programmer Hello, programmer

Page 1 of 1
Basic Data Types
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

The following lines show some C++ data types, their format specifiers and their most common bit
widths:

 int : 32 Bit integer.


 long long : 64 bit integer
 Char : 8 bit Characters & symbols
 Float : 32 bit real value
 Double : 64 bit real value

Reading

To read a data type, use the following syntax:

For example, to read a character followed by a double:

Printing

To print a data type, use the following syntax:

Page 1 of 2
For example, to print a character followed by a double:

Input
Only one line containing the following space-separated values: int, long long, char,
float and double respectively.

Output
Print each element on a new line in the same order it was received as input.

Don't print any extra spaces.

Example
standard input standard output
3 12345678912345 a 334.23 14049.30493 3
12345678912345
a
334.23
14049.3

Page 2 of 2
,

Simple Calculator
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given two numbers X and Y . Print the summation and multiplication and subtraction of these 2
numbers.

Input
Only one line containing two separated numbers X, Y (1 ≤ X, Y ≤ 105 ).

Output
Print 3 lines that contain the following in the same order:

1. “X + Y = summation result” without quotes.

2. “X * Y = multiplication result” without quotes.

3. “X - Y = subtraction result” without quotes.

Example
standard input standard output
5 10 5 + 10 = 15
5 * 10 = 50
5 - 10 = -5

Note
Be careful with spaces.

Page 1 of 1
,

Difference
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given four numbers A, B, C and D. Print the result of the following equation :
X = (A ∗ B) − (C ∗ D).

Input
Only one line containing 4 separated numbers A, B, C and D (−105 ≤ A, B, C, D ≤ 105 ).

Output
Print “Difference = 00 without quotes followed by the equation result.

Examples
standard input standard output
1 2 3 4 Difference = -10
2 3 4 5 Difference = -14
4 5 2 3 Difference = 14

Page 1 of 1
,

Area of a Circle
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
Given a number R calculate the area of a circle using the following formula:
Area = π * R2.
Note: consider π = 3.141592653.

Input
Only one line containing the number R (1 ≤ R ≤ 100).

Output
Print the calculated area, with 9 digits after the decimal point.

Example
standard input standard output
2.00 12.566370612

Note
* Use the data type double for this problem.

** Use setprecision ) 9 ) to print 9 digits after decimal point.

*** you can use function setprecision that are in #include<iomanip> library for Example :

Page 1 of 1
,

Digits Summation
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 64 megabytes

Given two numbers N and M . Print the summation of their last digits.

Input
Only one line containing two numbers N, M (0 ≤ N, M ≤ 1018 ).

Output
Print the answer of the problem.

Example
standard input standard output
13 12 5

Note
First Example :
last digit in the first number is 3 and last digit in the second number is 2.
So the answer is: (3 + 2 = 5)

Page 1 of 1
,

Summation from 1 to N
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 256 megabytes

Given a number N . Print the summation of the numbers that is between 1 and N (inclusive).

N
X
. i
i=1

Input
Only one line containing a number N (1 ≤ N ≤ 109 )

Output
Print the summation of the numbers that are between 1 and N (inclusive).

Examples
standard input standard output
3 6
10 55

Note
First Example :
the numbers between 1 and 3 are 1,2,3 .
So the answer is: (1 + 2 + 3 = 6)
Second Example :
the numbers between 1 and 10 are 1,2,3,4,5,6,7,8,9,10.
So the answer is: (1 + 2 + 3 + 4 + 5 + 6 +7 +8 + 9 + 10 = 55)

Page 1 of 1
Two numbers
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given 2 numbers A and B. Print floor, ceil and round of A/B


Note:

• Floor: Is a mathematical function that takes a real number X and its output is the greatest integer
less than or equal to X.

• Ceil: Is a mathematical function that takes a real number X and its output is the smallest integer
larger than or equal to X.

• Round: Is a mathematical function that takes a real number X and its output is the closest integer
to that number X.

For more clarification visit the links in the notes below.

Input
Only one line containing two numbers A and B (1 ≤ A, B ≤ 103 )

Page 1 of 2
Output
Print 3 lines that contain the following in the same order:

1. “floor A / B = Floor result” without quotes.

2. “ceil A / B = Ceil result” without quotes.

3. “round A / B = Round result” without quotes.

Examples
standard input standard output
10 3 floor 10 / 3 = 3
ceil 10 / 3 = 4
round 10 / 3 = 3
10 4 floor 10 / 4 = 2
ceil 10 / 4 = 3
round 10 / 4 = 3
10 6 floor 10 / 6 = 1
ceil 10 / 6 = 2
round 10 / 6 = 2

Note
Links:

• For Rounding method visit: https://www.mathsisfun.com/numbers/rounding-methods.html.

• For Flooring and Ceiling method visit: https://www.mathsisfun.com/sets/function-floor-ceiling.html.

Page 2 of 2
,

Welcome for you with Conditions


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 64 megabytes

Given two numbers A and B. Print “Yes” if A is greater than or equal to B. Otherwise print “No”.

Input
Only one line containing two numbers A and B (0 ≤ A, B ≤ 100).

Output
Print “Yes” or “No” according to the statement.

Examples
standard input standard output
10 9 Yes
5 5 Yes
5 7 No

Page 1 of 1
,

Multiples
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given two numbers A and B. Print “Multiples” if A is multiple of B or vice versa. Otherwise print “No
Multiples”.

Input
Only one line containing two numbers A, B (1 ≤ A, B ≤ 106 )

Output
Print the “Multiples” or “No Multiples” corresponding to the read numbers.

Examples
standard input standard output
9 3 Multiples
6 24 Multiples
12 5 No Multiples

Note
***A is said to be Multiple of B if B is divisible by A.
First Example :
9 is divisible by 3 , So the answer is: Multiples.
Second Example :
6 is not divisible by 24 but
24 is divisible by 6 , So the answer is: Multiples.
Third Example :
12 is not divisible by 5 and 5 is not divisible by 12.
So the answer is: No Multiples.

Page 1 of 1
,

Max and Min


Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 64 megabytes

Given 3 numbers A, B and C, Print the minimum and the maximum numbers.

Input
Only one line containing 3 numbers A, B and C (−105 ≤ A, B, C ≤ 105 )

Output
Print the minimum number followed by a single space then print the maximum number.

Examples
standard input standard output
1 2 3 1 3
-1 -2 -3 -3 -1
10 20 -5 -5 20

Page 1 of 1
,

The Brothers
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given two person names.


Each person has {“the first name” + “the second name”}
Determine whether they are brothers or not.
Note: The two persons are brothers if they share the same second name.

Input
First line will contain two Strings F1 , S1 which donates the first and second name of the 1s t person.
Second line will contain two Strings F2 , S2 which donates the first and second name of the 2n d person.

Output
Print “ARE Brothers” if they are brothers otherwise print “NOT”.

Examples
standard input standard output
bassam ramadan ARE Brothers
ahmed ramadan
ali salah ARE Brothers
ayman salah
ali kamel NOT
ali salah

Page 1 of 1
,

Capital or Small or Digit


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a letter X. Determine whether X is Digit or Alphabet and if it is Alphabet determine if it is


Capital Case or Small Case.
Note:

• Digits in ASCII ‘0’ = 48,‘1’ = 49 ....etc

• Capital letters in ASCII ‘A’ = 65, ‘B’ = 66 ....etc

• Small letters in ASCII ‘a’ = 97,‘b’ = 98 ....etc

Input
Only one line containing a character X which will be a capital or small letter or digit.

Output
Print a single line contains “IS DIGIT” if X is digit otherwise, print “ALPHA” in the first line followed
by a new line that contains “IS CAPITAL” if X is a capital letter and “IS SMALL” if X is a small
letter.

Examples
standard input standard output
A ALPHA
IS CAPITAL
9 IS DIGIT
a ALPHA
IS SMALL

Note
** recommended to read this to know more about ASCII Code https://www.javatpoint.com/ascii.

Page 1 of 1
,

Char
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 64 megabytes

Given a letter X. If the letter is lowercase print the letter after converting it from lowercase letter to
uppercase letter. Otherwise print the letter after converting it from uppercase letter to lowercase
letter
Note : difference between ’a’ and ’A’ in ASCII is 32 .

Input
Only one line containing a character X which will be a capital or small letter.

Output
Print the answer to this problem.

Examples
standard input standard output
a A
A a

Page 1 of 1
Calculator
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a mathematical expression. The expression will be one of the following expressions: A + B, A − B,
A ∗ B and A/B.
Print the result of the mathematical expression.

Input
Only one line contains A, S and B (1 ≤ A, B ≤ 104 ), S is either (+, −, ∗, /).

Output
Print the result of the mathematical expression.

Examples
standard input standard output
7+54 61
17*10 170

Note
For the dividing operation you should print the division without any fractions.

Page 1 of 1
,

First digit !
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 64 megabytes

Given a number X. Print ”EVEN” if the first digit of X is even number. Otherwise print ”ODD”.
For example: In 4569 the first digit is 4, the second digit is 5, the third digit is 6 and the fourth digit
is 9.

Input
Only one line containing a number X (999 < X ≤ 9999)

Output
If the first digit is even print 00 EV EN 00 otherwise print 00 ODD00 .

Examples
standard input standard output
4569 EVEN
3569 ODD

Note
Second Example :
In 3569 the first digit is 3 and its ODD.

Page 1 of 1
,

Coordinates of a Point
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given two numbers X, Y which donate coordinates of a point in 2D plan. Determine in which quarter
does it belong.
Note:

• Print Q1, Q2, Q3, Q4 according to the quarter in which the point belongs to.

• Print “Origem” If the point is at the origin.

• Print ”Eixo X” If the point is over X axis.

• Print “Eixo Y” if the point is over Y axis.

Input
Only one line containing two numbers X, Y (−1000 ≤ X, Y ≤ 1000).

Output
Print the answer to problem above.

Examples
standard input standard output
4.5 -2.2 Q4
0.1 0.1 Q1

Page 1 of 1
,

Age in Days
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a Number N corresponding to a person’s age (in days). Print his age in years, months and days,
followed by its respective message “years”, “months”, “days”.
Note: consider the whole year has 365 days and 30 days per month.

Input
Only one line containing a number N (0 ≤ N ≤ 106 ).

Output
Print the output, like the following examples.

Examples
standard input standard output
400 1 years
1 months
5 days
800 2 years
2 months
10 days
30 0 years
1 months
0 days

Page 1 of 1
,

Interval
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a number X. Determine in which of the following intervals the number X belongs to:
[0,25], (25,50], (50,75], (75,100]
Note:

• if X belongs to any of the above intervals print “Interval ” followed by the interval.

• if X does not belong to any of the above intervals print “Out of Intervals”.

• The symbol ’(’ represents greater than.

• The symbol ’)’ represents smaller than.

• The symbol ’[’ represents greater than or equal.

• The symbol ’]’ represents smaller than or equal.

For example:
[0,25] indicates numbers between 0 and 25.0000, including both.
(25,50] indicates numbers greater than 25: (25.00001) up to 50.0000000.

Input
Only one line containing a number X (−1000 ≤ X ≤ 1000).

Output
Print the answer to the problem above.

Examples
standard input standard output
25.1 Interval (25,50]
25.0 Interval [0,25]
100.0 Interval (75,100]
-25.2 Out of Intervals

Page 1 of 1
,

Sort Numbers
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 256 megabytes

Given three numbers A, B, C. Print these numbers in ascending order followed by a blank line and then
the values in the sequence as they were read.

Input
Only one line containing three numbers A, B, C (−106 ≤ A, B, C ≤ 106 )

Output
Print the values in ascending order followed by a blank line and then the values in the sequence as they
were read.

Examples
standard input standard output
3 -2 1 -2
1
3
3
-2
1
-2 10 0 -2
0
10
-2
10
0

Page 1 of 1
,

Float or int
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a number N . Determine whether N is float number or integer number.


Note:

• If N is float number then print “float” followed by the integer part followed by decimal part
separated by space.

• If N is integer number then print “int” followed by the integer part separated by space.

For more clarification see the examples below.

Input
Only one line containing a number N (1 ≤ N ≤ 103 )

Output
Print the answer required above.

Examples
standard input standard output
234.000 int 234
534.958 float 534 0.958

Page 1 of 1
,

Comparison
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given a comparison symbol S between two numbers A and B. Determine whether it is Right or W rong.
The comparison is as follows: A < B, A > B, A = B.
Where A, B are two integer numbers and S refers to the sign between them.

Input
Only one line containing A, S and B respectively (-100 ≤ A, B ≤ 100), S can be (‘<’, ‘>’,‘=’) without
the quotes.

Output
Print “Right” if the comparison is true, “Wrong” otherwise.

Examples
standard input standard output
5 > 4 Right
9 < 1 Wrong
4 = 4 Right

Page 1 of 1
,

Mathematical Expression
Input file: standard input
Output file: standard output
Time limit: 0.25 seconds
Memory limit: 256 megabytes

Given a mathematical expression. The expression will be one of the following expressions:
A + B = C, A − B = C and A ∗ B = C
where A, B, C are three numbers, S is the sign between A and B, and Q the ‘=’ sign
Print “Yes” If the expression is Right , Otherwise print the right answer of the expression.

Input
Only one line containing the expression: A, S, B, Q, C respectively (0 ≤ A, B ≤ 100, −105 ≤ C ≤ 105 )
and S can be (‘+’, ‘-’, ‘*’) without the quotation.

Output
Output either “Yes"(without the quotation) or the right answer depending on the statement.

Examples
standard input standard output
5 + 10 = 15 Yes
3 - 1 = 2 Yes
2 * 10 = 19 20

Page 1 of 1
Two intervals
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given the boundaries of 2 intervals. Print the boundaries of their intersection.


Note: Boundaries mean the two ends of an interval which are the starting number and the ending
number.

Input
Only one line contains two intervals [l1 , r1 ], [l2 , r2 ] where (1 ≤ l1 , l2 , r1 , r2 ≤ 109 ), (l1 ≤ r1 , l2 ≤ r2 ).
It’s guaranteed that l1 ≤ r1 and l2 ≤ r2 .

Output
If there is an intersection between these 2 intervals print its boundaries , otherwise print -1.

Examples
standard input standard output
1 15 5 27 5 15
2 5 6 12 -1

Note
First Example :

Second Example :

Page 1 of 2
Page 2 of 2
,

The last 2 digits


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given 4 numbers A, B, C and D. Print the last 2 digits from their Multiplication.

Input
Only one line containing four numbers A, B, C and D (2 ≤ A, B, C, D ≤ 109 ).

Output
Print the last 2 digits from their Multiplication.

Examples
standard input standard output
5 7 2 4 80
3 9 9 9 87

Note
First Example :
the Multiplication of 4 numbers is 5 * 7 * 2 * 4 = 280 so the answer will be the last 2 digits which are
80.
Second Example :
the Multiplication of 4 numbers is 3 * 9 * 9 * 9 = 2187 so the answer will be the last 2 digits which
are 87.

Page 1 of 1
Hard Compare
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

Given 4 numbers A, B, C and D. If AB > C D print “YES” otherwise, print “NO”.

Input
Only one line containing 4 numbers A, B, C and D (1 ≤ A, C ≤ 107 ) , (1 ≤ B, D ≤ 1012 )

Output
Print "YES"or "NO"according to the problem above.

Examples
standard input standard output
3 2 5 4 NO
5 2 4 2 YES
5 2 5 2 NO

Note
First Example :
32 = 9 and 54 = 625 then 9 < 625 so the answer is NO.
Second Example :
52 = 25 and 42 = 16 then 25 > 16 so the answer is YES.
Third Example :
52 = 25 and 52 = 25 then 25 = 25 so the answer is NO.

Page 1 of 1

You might also like