用vc6运行这个程序时,为什么运行不了,大家看看有什么错误的地方啊,检查了很久就是不知道哪儿出问题了
发布网友
发布时间:2022-04-24 21:11
我来回答
共1个回答
热心网友
时间:2023-10-11 09:55
#include <stdio.h>
#include <stdlib.h>
#define swap(h, i) do { int tmp = list[h]; list[h] = list[i]; list[i] = tmp; \
} while (0)
typedef enum { FALSE = 0, TRUE }BOOL;
bool next_permutation(int list [], size_t size) {
size_t head_item;
size_t item;
// find the sub completed list
for (item = size - 1; item > 0; item--) {
if (list[item - 1] < list[item]) {
break;
}
}
if (item == 0) {
// finished
return false;
}
else {
head_item = item - 1;
}
// find the next item:
// The first great than head_item
for (item = size - 1; item > head_item; item--) {
if (list[head_item] < list[item]) {
break;
}
}
swap(head_item, item);
// reverse the sub list
for (item = head_item + 1; item < size; item++, size--) {
swap(item, size - 1);
}
return true;
}
int main()
{
char a[2][15], b[15];
int i = 0, j = 0, k = 0, val = 0, max = 0, flag = 0, count = 0, match = 0;
int Tdata[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/*Initialize the array*/
Tdata[14] = Tdata[13] = 1;
FILE* fp = fopen("out.txt", "r");
if (fp == NULL)
{
printf("Wrong!");
return -1;
}
for (i = 0; i < 6435; i++)
{
long lOffset = 0; //用来记录a[0]读完后的位置
//取第i+1组数据
for (j = 0; j < 15; j++)
fscanf(fp, "%c", &a[0][j]);
/* for(j=0;j<15;j++)
printf("%c ",a[0][j]);
printf("---%d\n",i);*/
fscanf(fp, "\n");
/*The loop for creating the array and be use for comparing*/
do
{
for (j = 0; j < 15; j++)
b[j] = a[0][j];
lOffset = ftell(fp); //记录下当前位置
for (j = 0; j < 15; j++)
{
if (Tdata[j] == 1)
{
b[j] = 6;
}
}
//取第i+2,i+3.....组数组
for (k = i + 1; k < 6435; k++)
{
for (j = 0; j < 15; j++)
{
fscanf(fp, "%c", &a[1][j]);
}
for (j = 0; j < 15; j++)
{
if (a[1][j] == b[j] || b[j] == 6)
match++;
}
if (match == 15)
{
flag = 1;
count++;
}
match = 0;
fscanf(fp, "\n");
}
count += flag;
flag = 0;
//回到原来的位置
fseek(fp, lOffset, SEEK_SET);
} while (next_permutation(Tdata, sizeof(Tdata) / sizeof(int) ));
}
printf("%d", count);
return 0;
}