zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    dubbo官方文档笔记
    maven权威指南读书笔记
    ArrayList实现
    通过json把int[]转成Integer[]
    二分查找,希尔排序,欧几里得,斐波那契
    js快捷键设置
    java字符串和时间转换
    希尔排序动画
    vue render
    前端性能优化,算法
  • 原文地址:https://www.cnblogs.com/lulichuan/p/6357705.html
Copyright © 2011-2022 走看看