RQNOJ 3 Jam的计数法

一道模拟题,用的vector比用链表要方便很多,毕竟不需要自己写,因为是递增的,所以每一次你都要去检查最后一位加1之后有没有越界,如果没越界你就可以把他当前的字符删掉替换成他下一位的字符就可以了,如果越界了那么直接判断输出结束就可以了。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int s, t, w;
vector<char>a;
char total_last;//最后一位字符
int p;//判断变量
bool next(int end,int len){
    char last='a'+end-1;//序列中的最后一个
    while(a.size()<=len)
    {
        if(a.back()==last)
        {
            a.pop_back();//去掉最后一个
            --last;//最后一位向前移动
        }
        else
        {
            char temp=++a.back();
            if(temp>total_last)//越界判断
                p=1;
            while(a.size()<len){
                a.push_back(++temp);
            }
            return true;
        }
    }
    return false;
}

int main()
{
    cin>>s>>t>>w;
    for(int i=0;i<w;i++){
        char c; cin>>c;
        a.push_back(c);
    }
    total_last='a'+t-1;
    p=0;
    for(int i=1;next(t,w)&&i<=5;i++) {
            if(p)
            continue;
        for(vector<char>::iterator ite=a.begin();ite!=a.end();ite++){
            cout<<*ite;
        }
        cout<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/lulichuan/p/6357705.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值