码迷,mamicode.com
首页 > 其他好文 > 详细

题目:Jam的计数法(水题)

时间:2019-11-12 22:02:17      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:bre   problem   main   using   ret   ble   out   turn   strlen   

题目

传送门

思路

除了暴力我真没有想出其他的思路。。。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int b,t,w;
char a[105];
char s_s,s_t;
bool s[105];
bool pd()
{
    int tot=0;
    for(int i=s_t;i>=s_s;i--)
    {
        if(s[i])
            tot++;
        else
            break;
    }
    if(tot==w)
        return 1;
    return 0;
}
void add()
{
    int tot=0;
    for(int i=s_t;i>=s_s;i--)
    {
        if(s[i]==1)
        {
            s[i]=0;
            tot++;
        }
        else
        {
            for(int j=i;j>=s_s;j--)
            {
                if(s[j]==1)
                {
                    tot++;
                    s[j]=0;
                    for(int k=j+1;tot;k++,tot--)
                    {
                        s[k]=1;
                    }
                    return;
                }
                
            }
        }
    }
}
void pr()
{
    for(int i=s_s;i<=s_t;i++)
    {
        if(s[i])
        {
            cout<<(char)(i);
        }
    }
    cout<<'\n';
}
int main()
{
    //freopen("number.in","r",stdin);
    //freopen("number.out","w",stdout);
    cin>>b>>t>>w;
    cin>>a;
    s_s=b+'a'-1;
    s_t=t+'a'-1;
    int lena=strlen(a);
    for(int i=0;i<lena;i++)
        s[a[i]]=1;
    if(pd())
        return 0;
    for(int i=1;i<=5;i++)
    {
        add();
        pr();
        if(pd())
            break;
    }
    return 0;
}

题目:Jam的计数法(水题)

标签:bre   problem   main   using   ret   ble   out   turn   strlen   

原文地址:https://www.cnblogs.com/loney-s/p/11845415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!