zoukankan      html  css  js  c++  java
  • 枚举合法字符使之按字典序输出——pku3049

    View Code
    #include<stdio.h>
    #include
    <iostream>
    #include
    <algorithm>
    using namespace std;

    char a[29],b[29];

    bool cmp(char a,char b)
    {
    return a>b;//大到小
    //使abc为中a为最高位与all->1枚举相符
    }

    int main()
    {
    int n,t,i,j;
    while(scanf("%d%d",&n,&t)!=EOF)
    {
    getchar();
    scanf(
    "%c",&a[0]);
    for(i=1;i<t;i++)
    {
    scanf(
    " %c",&a[i]);
    }

    sort(
    &a[0],&a[t],cmp);

    int all=1;
    for(i=1;i<=t;i++)
    all
    *=2;

    int add=0;
    for(i=all;i>=1;i--)//大到小
    {
    add
    =0;
    bool rt=0;
    int fadd=0;
    for(j=0;j<t;j++)
    {
    if(i&(1<<j))
    {
    if(a[j]=='a'||a[j]=='e'||a[j]=='i'||a[j]=='o'||a[j]=='u')
    rt
    =1;
    else
    fadd
    ++;
    b[add]
    =a[j];
    add
    ++;
    }
    }
    if(add==n&&rt==1&&fadd>=2)
    {
    for(j=n-1;j>=0;j--)
    printf(
    "%c",b[j]);
    printf(
    "\n");
    }
    }
    }
    }
  • 相关阅读:
    第二周学习总结
    2019春总结作业
    第十二周作业
    第十一周作业
    第九周作业
    第八周作业
    第七周作业
    第六周作业
    第五周课程总结与报告
    Java第四周编程总结
  • 原文地址:https://www.cnblogs.com/huhuuu/p/2000232.html
Copyright © 2011-2022 走看看