Sitemap

Day 36 Learning C && Python: Practice Problems

3 min readJan 6, 2023

--

Press enter or click to view image in full size

I lost my streak on Codechef at 27 days. Shit! I didn’t do any practice problems yesterday because I was lazy a just walked round and explored Naples all day. Twenty more days until I return to Vegas. I’ve been here, in Naples Italy, for 10 days and feel I haven’t advanced an inch in programing.

Problem 1. Sum It

Difficulty Rating: 308

Bob received an assignment from his school: he has two numbers A and B, and he has to find the sum of these two numbers.
Alice, being a good friend of Bob, told him that the answer to this question is C.
Bob doesn’t completely trust Alice and asked you to tell him if the answer given by Alice is correct or not.
If the answer is correct print "YES", otherwise print "NO" (without quotes).

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • The first and only line of each test case consists of three space-separated integers A, B, and C.

Output Format

For each test case, output on a new line the answer: YES if Alice gave the right answer, and NO otherwise.

Each character of the output may be printed in either uppercase or lowercase, i.e, the outputs Yes, YES, yEs and yes will be treated as equivalent.

Constraints

  • 1 ≤ T ≤ 100
  • 0 ≤ A, B, C ≤ 100

Easy 300 rated problem. Not much to explain here. If variables “a” plus “b” are equal to “c” then print “yes”, or else print “no”.

#include <stdio.h>

int main(void)
{
int t;
scanf("%d", &t);
while(t--)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a + b == c)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
for t in range(int(input())):
a, b, c = map(int, input().split())
print("Yes" if a + b == c else " No")

Problem 2. Indivisible

Difficulty Rating: 787

Get jay.dez’s stories in your inbox

Join Medium for free to get updates from this writer.

Alice thinks Bob has very weak math skills.
Alice gave Bob three numbers A, B, and C and challenged him to find any positive integer K strictly less than 100 such that none of the three numbers are divisible by K.

Help Bob find one such integer K.

Under the given constraints, a valid K will always exist.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • The first and only line of each test case contains three space-separated integers A, B, and C.

Output Format

For each test case, output on a new line any positive integer K less than 100100 that does not divide any of A, B, or C.

Constraints

  • 1 ≤ T ≤ 1000
  • 2 ≤ A, B, C ≤ 100
#include <stdio.h>

int main(void)
{
int t;
scanf("%d", &t);
while(t--)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
for(int k = 1; k < 100; k++)
{
if(a%k != 0 && b%k != 0 && c%k != 0)
{
printf("%d\n", k);
break;
}
}
}
return 0;
}

Lines:

1. Kept the for-loop counter integer as “k” instead of “i” since we are looking for “k”. The constraints call for “k” being greater than one and less than 100, hence the “k = 1; k < 100”

13–15 if “k” doesn’t divide evenly into the other variables, print the current value of “k”

16. break out of the loop once it finds the indivisible variable, or it’ll keep going.

for t in range(int(input())):
a, b, c = map(int, input().split())
for k in range(1, 100):
if a%k != 0 and b%k != 0 and c%k != 0:
print(k)
break

Very similar setup to writing it in C. With the for-loop I set the range to the constraints in the problem 1–100. Print the counter variable and then break.

Datacamp.com

# Definition of pi_string
pi_string = “3.1415926” # Convert pi_string into float: pi_float pi_float = float(pi_string)

--

--

jay.dez
jay.dez

Written by jay.dez

no offense shortstack but you give me the creeps