Compile Error
/in/foo.c:7:1: error: unknown type name 'bool' bool used[maxn]; ^~~~ /in/foo.c: In function 'GetNext': /in/foo.c:14:17: error: 'false' undeclared (first use in this function) if (used[x] == false) ^~~~~ /in/foo.c:14:17: note: each undeclared identifier is reported only once for each function it appears in /in/foo.c:16:13: error: 'true' undeclared (first use in this function) used[x] = true; ^~~~ /in/foo.c: At top level: /in/foo.c:21:1: error: unknown type name 'bool' bool check() ^~~~ /in/foo.c: In function 'check': /in/foo.c:26:36: error: 'false' undeclared (first use in this function) if ((A + B + x) % n != C) return false; ^~~~~ /in/foo.c:29:9: error: 'true' undeclared (first use in this function) return true; ^~~~ /in/foo.c: At top level: /in/foo.c:31:1: error: unknown type name 'bool' bool isPrune() ^~~~ /in/foo.c: In function 'isPrune': /in/foo.c:34:10: error: 'true' undeclared (first use in this function) return true; ^~~~ /in/foo.c:42:9: error: 'false' undeclared (first use in this function) return false; ^~~~~ /in/foo.c: In function 'dfs': /in/foo.c:47:19: error: 'true' undeclared (first use in this function) if (isPrune() == true) return; ^~~~ /in/foo.c:57:18: error: 'false' undeclared (first use in this function) if (used[i] == false) ^~~~~ /in/foo.c: In function 'main': /in/foo.c:86:40: error: 'false' undeclared (first use in this function) for (int i = 0; i < n; i++) used[i] = false; ^~~~~ /in/foo.c: In function 'check': /in/foo.c:30:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ /in/foo.c: In function 'isPrune': /in/foo.c:43:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
代码
#include<stdio.h>
#define maxn 27
int a[maxn], b[maxn], c[maxn];
int result[maxn], Next[maxn], n, p;
char s1[maxn], s2[maxn], s3[maxn];
bool used[maxn];
int id(char c)
{
return c - 'A';
}
void GetNext(int x)
{
if (used[x] == false)
{
used[x] = true;
Next[p++] = x;
}
return;
}
bool check()
{
for (int i = n - 1, x = 0; i >= 0; i--)
{
int A = result[a[i]], B = result[b[i]], C = result[c[i]];
if ((A + B + x) % n != C) return false;
x = (A + B + x) / n;
}
return true;
}
bool isPrune()
{
if (result[a[0]] + result[b[0]] >= n)//最高位的和大于n
return true;
for (int i = n - 1; i >= 0; i--)
{
int A = result[a[i]], B = result[b[i]], C = result[c[i]];
if (A == -1 || B == -1 || C == -1) continue;
if ((A + B) % n != C && (A + B + 1) % n != C)
return true;
}
return false;
}
void dfs(int x)
{
if (isPrune() == true) return;
if (x == n) {
if (check() == true) {
for (int i = 0; i < n; i++)
printf("%d ", result[i]);
}
return;
}
for (int i = n - 1; i >= 0; i--)
{
if (used[i] == false)
{
result[Next[x]] = i;
used[i] = true;
dfs(x + 1);
result[Next[x]] = -1;//回退
used[i] = false;
}
}
return;
}
int main()
{
scanf("%d", &n);
scanf("%s%s%s", s1, s2, s3);
for (int i = 0; i < n; i++)
{
a[i] = id(s1[i]);
b[i] = id(s2[i]);
c[i] = id(s3[i]);
result[i] = -1;
}
for (int i = n - 1; i >= 0; i--)
{
GetNext(a[i]);
GetNext(b[i]);
GetNext(c[i]);
}
for (int i = 0; i < n; i++) used[i] = false;
dfs(0);
return 0;
}
信息
- 递交者
- 类型
- 递交
- 题目
- P1001 虫食算
- 语言
- C
- 递交时间
- 2020-06-07 12:09:38
- 评测时间
- 2020-06-07 12:09:38
- 评测机
- 分数
- 0
- 总耗时
- 0ms
- 峰值内存
- 0 Bytes