zl程序教程

您现在的位置是:首页 >  后端

当前栏目

暴力激活成功教程密码 – C++ 递归方法实现

2023-06-13 09:13:41 时间

大家好,又见面了,我是你们的朋友全栈君。

问题描述: 暴力激活成功教程密码 假设有一个 4 位字母密码,每位密码是 a~e 之间的小写字母 你能否编写一段代码,来暴力激活成功教程该密码?(可重复排序)

#include <iostream>
#include<string>

using std::string;
using namespace std;

void BreakPassword( string Words, int PasswordLen, string result)
{
    if (result.length() == PasswordLen)
    {
        //C++中string类型不能直接输出,需加头问题#include<string>,不能用#include<string.h>
        cout << result << "    ";
        return;
    }

    for (int i = 0; i < Words.length(); ++i)
    {
        string newResult = result;
        newResult.insert( newResult.end(), Words[i] );
        BreakPassword(Words, PasswordLen, newResult);
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    int passwordLen = 4;
    string words("abcde");
    string result = "";
    
    BreakPassword(words, passwordLen, result);

    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/172189.html原文链接:https://javaforall.cn