HDU 1716 排列2

题不难,格式真坑,PE了两天才找到错误,最后一组0 0 0 0数据是不能和上一组有空行的,之前一直PE的原因是下一组数据先空行再输入导致最后一组0 0 0 0怎么都有空行

PE的:

#include<iostream>
#include<algorithm>

using namespace std;

int main(){

    int a[4];

    int flag=0;




        while(cin>>a[0]>>a[1]>>a[2]>>a[3]&&a[0]+a[1]+a[2]+a[3]!=0){
            int  flag2 = 0;
			do{
                    if(a[0]==0)
                        continue;
            static int temp = a[0];

			if(temp==a[0]&&flag2){
 			cout<<" ";}


			else if(flag2)
				cout<<endl;
                cout<<a[0]<<a[1]<<a[2]<<a[3];
            flag2 = 1;
            temp=a[0];
          }while(next_permutation(a,a+4));
		  if(a[0]+a[1]+a[2]+a[3]!=0&&flag){
          cout<<endl;
          flag=1;}
     cout<<endl;
     if(a[0]+a[1]+a[2]+a[3]!=0)
     cout<<endl;
    }


	return 0;
}

AC的
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a[4];


    while(cin>>a[0]>>a[1]>>a[2]>>a[3]&&a[0]+a[1]+a[2]+a[3]!=0){
        static int flag = 0;
        if(flag){
            cout<<endl;}
            flag = 1;
            sort(a,a+4);
        int  flag2 = 0;
        do{
                if(a[0]==0)
                    continue;
        static int temp = a[0];

        if(temp==a[0]&&flag2){
        cout<<" ";}

        else if(flag2)
            cout<<endl;
            cout<<a[0]<<a[1]<<a[2]<<a[3];
        flag2 = 1;
        temp=a[0];
      }while(next_permutation(a,a+4));

 if(a[0]+a[1]+a[2]+a[3]!=0)
 cout<<endl;
}


return 0;
}


原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256477.html