Day 1 - Young Physicist | C++
- Ayush Mahajan
- Aug 28, 2022
- 1 min read
Updated: Sep 26, 2022

The journey starts from the simplest questions only. So starting with the first question of the list - Young Physicist. You should always try it out yourself first.
To solve this question remember that for a body to be in equilibrium, the sum for all x, y, and z vectors should be zero. You can code it this way:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int x[n], y[n], z[n];
for(int i = 0; i < n; i++){
cin >> x[i] >> y[i] >> z[i];
}
// Calculating sum for x - axis;
int x_sum = 0;
for(int i = 0; i < n; i++){
x_sum += x[i];
}
// Calculating sum for y - axis;
int y_sum = 0;
for(int i = 0; i < n; i++){
y_sum += y[i];
}
// Calculating sum for z - axis;
int z_sum = 0;
for(int i = 0; i < n; i++){
z_sum += z[i];
}
if(x_sum == 0 && y_sum == 0 && z_sum == 0){
cout << "YES\n";
}
else {
cout << "NO\n";
}
}Submission Link If you want to solve with less code -
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, x = 0, y = 0, z = 0;
cin >> n;
for(int i = 0; i < n; i++){
int a,b,c;
cin >> a >> b >> c;
x+=a;
y+=b;
z+=c;
}
if(x == 0 && y == 0 && z == 0){
cout << "YES";
}
else{
cout << "NO";
}
}![Day 44 | Binary Search Practice [Leetcode] | C++](https://static.wixstatic.com/media/fbea2a_167f1b66234f4d30b91bcf5b517f83f3~mv2.jpg/v1/fill/w_980,h_490,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/fbea2a_167f1b66234f4d30b91bcf5b517f83f3~mv2.jpg)
![Day 43 | Graph and Tree Practice [Leetcode] II | C++](https://static.wixstatic.com/media/fbea2a_361d6f7cd90c431b9f25518e1503da94~mv2.jpg/v1/fill/w_980,h_490,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/fbea2a_361d6f7cd90c431b9f25518e1503da94~mv2.jpg)
![Day 42 | Graph Practice [LeetCode] | C++](https://static.wixstatic.com/media/fbea2a_6570bb28577149f19db06704d542789a~mv2.jpg/v1/fill/w_980,h_490,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/fbea2a_6570bb28577149f19db06704d542789a~mv2.jpg)
Comments