51 nod 1090 3个数和为0

来源:互联网 发布:json对象如何转成数组 编辑:程序博客网 时间:2024/05/29 02:56

与1001类似   把代码稍微改了改   

#include <queue>#include <stdio.h>#include <iostream>#include <stdlib.h>#include <cmath>#include<algorithm>using namespace std;int main(){    int n;    while(cin>>n){       bool temp=false;       int Array[n];       for(int i = 0 ;i < n;i++){       cin>>Array[i];       }       sort(Array,Array+n);       for(int i = 0; i < n ;i++)       {           if(Array[i]+Array[n-1]+Array[n-2]<0)            continue;           for(int j = i+1;j < n;j++){            for(int z = j +1 ; z < n&&Array[i]+Array[j]+Array[z]<=0;z++)            {               if(Array[i]+Array[j]+Array[z]==0)               {                   temp=true;                  cout<<Array[i]<<" "<<Array[j]<<" "<<Array[z]<<endl;               }           }           }       }    if(!temp)        cout<<"No Solution"<<endl;    }    return 0;}


0 0