zoukankan      html  css  js  c++  java
  • HDU 1716 排列2 (格式问题+排列)

    题意:。

    析:我们完全可以STL里面的函数next_permutation(),然后方便,又简单,这个题坑就是在格式上。

    行末不能有空格,结尾不能有空行,不大好控制,必须控制好第一次数。

    这个题本应该用DFS的,去枚举,也挺简单的,在这就不说了。

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <cstring>
    #include <map>
    #include <cctype>
    
    using namespace std;
    const int maxn = 1000 + 5;
    int a[5];
    
    int main(){
    //    freopen("in.txt", "r", stdin);
        int kase = 0;
        while(true){
            int sum = 0;
            for(int i = 0; i < 4; ++i){
                scanf("%d", &a[i]);
                sum += a[i];
            }
            if(!sum)  break;
            if(kase)  printf("
    ");
            sort(a, a+4);
    
            int t = -1;
            bool ok = false;
            do{
                if(!a[0])  continue;
    
                if(a[0] != t){
                    t = a[0];
                    if(ok)  printf("
    ");
                    ok = true;
                }
                else  printf(" ");
    
                for(int i = 0; i < 4; ++i)
                    printf("%d", a[i]);
            }while(next_permutation(a, a+4));
    
            printf("
    ");
            ++kase;
        }
        return 0;
    }
    
  • 相关阅读:
    js中replace的正则替换
    ios沙盒路径
    Android开源框架
    小知识点
    __NSCFConstantString && __NSPlaceholderDictionary
    iq 格式分析
    C 函数
    Xcode报错
    XMPP Server
    H5网站借鉴
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5555934.html
Copyright © 2011-2022 走看看