zoukankan      html  css  js  c++  java
  • C

    Problem description

    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.

    Input

    The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zicoordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).

    Output

    Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.

    Examples

    Input

    3
    4 1 7
    -2 4 -1
    1 -5 -3

    Output

    NO

    Input

    3
    3 -1 7
    -5 2 -4
    2 -1 -3

    Output

    YES
    解题思路:题目的意思就是检查n行3列中每一列数字之和是否都为0,是的话为"YES",否则为"NO",水过。
    AC代码:
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int n,a[105][3],b[3];
     5     cin>>n;
     6     memset(b,0,sizeof(b));
     7     for(int i=0;i<n;++i){
     8         for(int j=0;j<3;++j){
     9             cin>>a[i][j];b[j]+=a[i][j];
    10         }
    11     }
    12     bool flag=false;
    13     for(int i=0;i<3;++i)
    14         if(b[i]!=0){flag=true;break;}
    15     if(flag)cout<<"NO"<<endl;
    16     else cout<<"YES"<<endl;
    17     return 0;
    18 }
  • 相关阅读:
    vue-element 时间选择器datepicker 第二次展示change无效,数据刷新页面不刷新
    uniapp
    mysql
    python
    pycharm
    从maven的debug compile到java的编译时注解(与springboot项目整合)
    关于H5+实现APP检查自动更新与 调用 plus.runtime.install 弹出不了安装界面问题
    Linux常用命令
    mybatis中sql语句必须用${}而不能不用#{}的情况
    Mybatis映射文件中的参数传递
  • 原文地址:https://www.cnblogs.com/acgoto/p/9128850.html
Copyright © 2011-2022 走看看