hdu1716

来源:互联网 发布:外国域名注册网站 编辑:程序博客网 时间:2024/04/28 23:01

坑爹的格式。。

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int a[4],hash1[4],vis[4],hash2[10000];int flag,temp,cnt;void Show(){    int num = hash1[0] * 1000 + hash1[1] * 100 + hash1[2] * 10 + hash1[3];    if(hash2[num]) return;    else{        hash2[num] = 1;        if(temp != hash1[0]){            cnt = 0;            temp = hash1[0];            flag++;            if(flag) printf("\n");        }        if(cnt != 0) printf(" ");        for(int i = 0;i < 4;i++){            printf("%d",hash1[i]);        }        cnt++;    }    return ;}void Dfs(int x){    if(x == 4){        Show();        return ;    }    for(int i = 0;i < 4;i++){        if(x == 0 && a[i] == 0)continue;        if(!vis[i]){            hash1[x] = a[i];            vis[i] = 1;            Dfs(x + 1);            vis[i] = 0;        }    }}int main(){    int k = 0;    while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])){        if(!a[0] && !a[1] && !a[2] && !a[3]) break;        if(k)printf("\n");        sort(a,a+4);        memset(hash1,0,sizeof(hash1));        memset(hash2,0,sizeof(hash2));        memset(vis,0,sizeof(vis));        temp = -1,flag = -1,cnt = 0;        Dfs(0);        printf("\n");        k++;    }    return 0;}


0 0