Codeforces 69A: Young Physicist The Problem: A boy is given a boy with a set of forces acting on it in x, y and z space. He needs to find out if the body is in equilibrium or not. For a body to be in equilibrium, all forces on it must be balanced ( Σ(F) == 0 ). So, we need to find out if the forces in x, y, z plane individually are 0. The Solution: The Algorithm: 1) Take n input. Declare sums of x, y, z and set them to 0. 2) Take a loop and make it run n times. 3) Take the x, y, z inputs and sum them up with their respective sum variables. 4) Check to see if all of them are zero. If true, print YES. Else print NO The Code: #include <bits/stdc++.h> #define fastio ios :: sync_with_stdio ( 0 ); cin . tie ( 0 ); cout . tie ( 0 ); using namespace std ; int main () { fastio ; int n ; cin >> n ; int x_sum , y_sum ,...
Codeforces 236A: Boy or Girl The Problem: A person tries to figure out how to distinct a boy and girl in an online chat platform. A boys account will have odd number of distinct characters. Here, distinct characters mean the total number of the type of characters. Ex: string: AB distinct chars: 2 (there are two types: A and B) string: ABBAACCD distinct chars: 4 (there are four types: A, B, C and D) The Solution: The Algorithm: 1) take a string 2) take a set of chars and insert each char in string into set. 3) count the number of chars in the set 4) if odd print "IGNORE HIM", else "CHAT WITH HER!". NOTE: We used set here because it does not take ANY DUPLICATE VALUES. If a value is already in the set, it will ignore it. The Code: #include <bits/stdc++.h> #define fastio ios :: sync_with_stdio ( 0 ); cin . tie ( 0 ); cout . tie ( 0 ); using namespace std ; int main () { string str ; cin ...
Codeforces 71A: Way Too Long Words You might've heard of codeforces. If not, let me tell you that they are one of the most challenging online judges in the internet right now. Their problem sets are very unique and will pick your brain a lot. Today, I'll walk you through such a problem. Problem 71A: Way Too Long Words. What the problem wants? The problem basically tells us to take a word and if it is way too long we need to convert it to a shorter form (a guideline which they have given). The author states that any word bigger than 10 is a long word and must be shortened in the way that: the first letter will be its starting letter. The next will be the number of characters present between the starting and ending letter, and finally, the last letter will be its ending letter. Example: initialization i12n There are 12 letter between i and n. The Solution: Algorithm: 1) Take the word input 2) check if it's less than or equal to 10. 3) If yes, simple print the word. 4) Else, ...
Comments
Post a Comment