-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
46 lines (41 loc) · 1.21 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <QtMath>
#include <QFileInfoList>
#include "utils.h"
//对长度为len,值为-1的数组a随机填入[0,1,....len-2]
//最后一个没有填的元素保持-1,对应空白
void permute(int* a,int len){
for (int num=0;num<len-1;num++){
//随机挑选一个位置将num放入
int j;
while(1){
j=qrand()%len;//插入的下标为[0,len-1]
if (a[j]==-1)
break;
}
a[j]=num;
}
}
void copy(int** dest, int** src, int m, int n) {
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
dest[i][j] = src[i][j];
}
bool same(int** a, int** b, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] != b[i][j])
return false;
}
}
return true;
}
QStringList getdirnames(const QString &path, const QStringList &filters){
QDir dir(path);
QFileInfoList list=dir.entryInfoList(filters,QDir::Files|QDir::NoSymLinks);
QStringList ret;
for (int i=0,len=list.length();i<len;i++){
QFileInfo fileinfo=list.at(i);
ret.append(fileinfo.baseName());
}
return ret;
}