• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            轉 ACM/ICPC 中的STL——next_permutation()

            在對元素進行字典序組合排列時可以使用STL提供的next_permutation()和prev_permutation()。這里例舉兩種簡單的應用。

            POJ 1731 Orders (使用默認比較方法)

            #include<stdio.h>
            #include<string.h>
            #include<algorithm>
            using namespace std;

            int main()
            {
                int i,j,k,m,n;
                char a[210];   
                while(gets(a) && a[0])
                {       
                    n=strlen(a);
                    sort(a,a+n);    //先排序
                    printf("%s\n",a);
                    while(next_permutation(a,a+n))    //返回bool,若無更大的字典序排列返回false
                        printf("%s\n",a);
                }
                return 0;
            }

            POJ 1256 Anagram (需要自定義cmp函數)

            #include<algorithm>
            #include<iostream>
            #include<cstring>
            #include<ctype.h>

            using namespace std;

            int cmp(char a, char b)      //自定義cmp函數
            {
                if(tolower(a)==tolower(b))
                    return a<b;
                return tolower(a)<tolower(b);
            }

            int main()
            {
                char s[15];
                int i,j,k,m,n;
                cin>>n;
                cin.ignore();
                while(n--)
                {
                    cin.getline(s,15);
                    k=strlen(s);
                    sort(s,s+k,cmp);
                    cout<<s<<endl;
                    while(next_permutation(s,s+k,cmp))
                        cout<<s<<endl;
                }
                return 0;
            }

            posted on 2008-08-27 00:01 gong 閱讀(521) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿(6)

            隨筆檔案

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产一区二区三区不卡 | 久久99久久99小草精品免视看| 亚洲AV无码一区东京热久久 | 久久国产香蕉视频| 狠狠综合久久综合88亚洲| 999久久久免费精品国产| 品成人欧美大片久久国产欧美...| 久久夜色撩人精品国产小说| 亚洲国产精品高清久久久| 久久99精品久久久久久9蜜桃| 久久偷看各类wc女厕嘘嘘| 亚洲精品高清久久| 91久久精品91久久性色| 99蜜桃臀久久久欧美精品网站 | 人人狠狠综合88综合久久| 久久99中文字幕久久| 亚洲精品无码成人片久久| 九九精品久久久久久噜噜| 久久WWW免费人成—看片| 狠狠色婷婷综合天天久久丁香| 久久精品人人做人人爽电影| 欧美日韩成人精品久久久免费看| 久久精品免费一区二区三区| 亚洲国产精品无码成人片久久| 亚洲精品国产第一综合99久久| 久久精品国产亚洲网站| 久久精品国产亚洲AV香蕉| 日本强好片久久久久久AAA| 亚洲中文字幕无码久久综合网| 久久亚洲日韩看片无码| 怡红院日本一道日本久久| a高清免费毛片久久| 九九久久99综合一区二区| 72种姿势欧美久久久久大黄蕉| 久久亚洲精品人成综合网| 久久精品中文騷妇女内射| 久久成人国产精品| 99国产精品久久| 久久久久久av无码免费看大片| 久久精品国产精品亚洲人人| 四虎影视久久久免费|