界面比较简洁,如有需要请大家自行完善!!!
头文件
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_text.h"class text : public QMainWindow
{
Q_OBJECTpublic:
text(QWidget *parent = nullptr);
~text();void ParseStringToVector(const QString& strData, std::vector<std::vector<int>>& vecData);
void Paxi(std::vector<std::vector<int>> all_num, std::vector<int> single_num, int num);
std::vector<std::string> result_str;private:
Ui::textClass* m_ui;;
};
#include "text.h"
#include <string.h>
#include <iostream>using namespace std;
text::text(QWidget* parent)
: QMainWindow(parent),
m_ui(new Ui::textClass)
{
m_ui->setupUi(this);
connect(m_ui->pushButton , &QPushButton::clicked, this, [=]
{
m_ui->listWidget->clear();
QString m_input = m_ui->lineEdit->text();
vector<vector<int>> m_listData;
ParseStringToVector(m_input, m_listData);
std::vector<int> single_num;
Paxi(m_listData, single_num, 0);
});}
text::~text()
{
}void text::ParseStringToVector(const QString& strData, vector<vector<int>>& vecData)
{
vecData.clear();
auto rows = strData.split(";");
for (auto row : rows)
{
if (row == "")break;
auto values = row.split(",");
std::vector<int> rowData;
for (auto value : values)
{
rowData.push_back(value.toInt());
}
vecData.push_back(rowData);
}
}
void text::Paxi(std::vector<std::vector<int>> all_num, std::vector<int> single_num, int num)
{
for (int i = 0; i < all_num[num].size(); i++)
{
if (num < all_num.size() - 1)
{
if (num < single_num.size())
{
single_num[num] = all_num[num][i];
}
else
{
single_num.push_back(all_num[num][i]);
}
Paxi(all_num, single_num, num + 1);
}
else
{
//single_num.push_back(all_num[num][i]);
std::string str;
for (int j = 0; j < single_num.size(); j++)
{
str += to_string(single_num[j]) + ",";
}
str += to_string(all_num[num][i]);
result_str.push_back(str);
m_ui->listWidget->addItem(QString::fromStdString(str));
}
}
}
主函数
#include "text.h"
#include <QtWidgets/QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
text w;
w.show();
return a.exec();
}