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 96A: Football The Problem: A boy watching football keeps noting down the number of players in both teams with 0 being the players from one team and 1 being the players from another team. He deduces that if minimum 7 players of the same team stand side by side, the situation would become dangerous. Ex: 01001. Situation is not dangerous because no 7 players of the same team are standing side by side. Ex: 1000000001. Situation is dangerous because 7 players of the same team are side by side. Ex: 1011011111111011. Situation is dangerous because 7 players of the same team are side by side. The Solution: The Algorithm: 1) take a string input 2) start counting the string from 1 until strings length (we start from 1 because we would want to check the chars of current index string with the previous index string) using a for loop. 3) check if current index char matches with last index char. 4) if it does then we increment the counter and check if it's 7 or not. If it is then we r...
Comments
Post a Comment