69A. Young Physicist
- time limit per test2 seconds
- memory limit per test256 megabytes
- inputstandard input
- outputstandard output
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
一个叫Vasya的家伙在上高中的最后一年级。一天,瓦西亚决定观看他最喜欢的曲棍球队的一场比赛。而且,由于男孩非常喜欢曲棍球,甚至比物理更爱曲棍球,他忘了做作业。具体来说,他忘了完成物理任务。第二天,老师对瓦西亚非常生气,决定教训他一顿。他给了这个懒惰的学生一个看似简单的任务:在太空中给你一个空闲的身体和影响它的力量。实体可以被视为具有坐标(0;0;0)的材质点。瓦西亚只需回答它是否处于平衡状态。“小菜一碟”——瓦西亚想,我们只需要检查所有向量之和是否等于0。于是,瓦西亚开始解决这个问题。但后来发现,这些力量可能会越来越多,没有你的帮助,瓦西亚无法应对。帮帮他。编写一个程序,根据给定的力矢量确定物体是空闲还是移动。
Input
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the x coordinate, the y coordinate and the z coordinate of the force vector, applied to the body ( - 100 ≤ x, y, z ≤ 100).
第一行包含一个正整数n(1) ≤ N ≤ 100)然后,遵循N个包含三个整数的N行:施加于身体的力向量的x坐标、y坐标和z坐标 ( - 100 ≤ x, y, z ≤ 100).
Output
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
如果身体处于平衡状态,打印“是”,如果身体处于平衡状态,打印“否”。
Examples
input1
3
4 1 7
-2 4 -1
1 -5 -3
output1
NO
input2
3
3 -1 7
-5 2 -4
2 -1 -3
output2
YES
Solution
!注意初始化需要分别进行!!!
Code
#include <iostream>
using namespace std;
//69A. Young Physicist
int main(){
int n = 0;
cin >> n;
int sumx = 0;
int sumy = 0;
int sumz =0;
for(int i = 0;i < n;i++){
int x,y,z =0;
cin >> x >> y >> z;
sumx += x;
sumy += y;
sumz += z;
}
if(sumx == 0 && sumy == 0 && sumz == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}