zoukankan      html  css  js  c++  java
  • 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;
    }


  • 相关阅读:
    mysql 添加自增长ID(序列方式)
    获取本地IP地址信息
    Intellij 快捷键
    java转换汉字为首字母搜索,
    gitee在linux下自动备份
    七牛云续费dns的ssl证书
    shiro 的realm的授权
    realme的shiro简单实现方法
    shiro初探,最简单的认证,通过ini文件。
    git config file
  • 原文地址:https://www.cnblogs.com/zhangmingzhao/p/7256477.html
Copyright © 2011-2022 走看看