提示compile error,怎么办。。(C++)
题目是开心的金明。#include<iostream>usingnamespacestd;inti1,i2,i,max=0,n,space;intthings[26][2...
题目是开心的金明。
#include <iostream>
using namespace std;
int i1,i2,i,max=0,n,space;
int things[26][2];
int main()
{
cin>>space>>n;
void ah(int,int,int,int);
for (i=1;i<=n;i++)
cin>>things[i][0]>>things[i][1];
for (i=1;i<=n;i++)
for (i1=1;i1<=n+1-i;i1++)
ah(i1,1,things[i1][0]*things[i1][1],things[i1][0]);
cout<<max;
return 0;
}
void ah(int a,int b,int c,int d)
{
int u;
if (b=i && c>max && d<=space)
max=c;
if (b!=i && d<space)
for(u=a+1;u<=n;u++)
ah(u,b+1,c+things[u][0]*things[u][1],d+things[u][0]);
}
接下来是错误信息。
//RQNOJ:UserCode\547871.cpp: In function `int main()’:
//RQNOJ:UserCode\547871.cpp:14: error: `max’ undeclared (first use this function)
//RQNOJ:UserCode\547871.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)
//RQNOJ:UserCode\547871.cpp: In function `void ah(int, int, int, int)’:
//RQNOJ:UserCode\547871.cpp:21: error: `max’ undeclared (first use this function)
//RQNOJ:UserCode\547871.cpp:26:2: warning: no newline at end of file
求赐教。。 展开
#include <iostream>
using namespace std;
int i1,i2,i,max=0,n,space;
int things[26][2];
int main()
{
cin>>space>>n;
void ah(int,int,int,int);
for (i=1;i<=n;i++)
cin>>things[i][0]>>things[i][1];
for (i=1;i<=n;i++)
for (i1=1;i1<=n+1-i;i1++)
ah(i1,1,things[i1][0]*things[i1][1],things[i1][0]);
cout<<max;
return 0;
}
void ah(int a,int b,int c,int d)
{
int u;
if (b=i && c>max && d<=space)
max=c;
if (b!=i && d<space)
for(u=a+1;u<=n;u++)
ah(u,b+1,c+things[u][0]*things[u][1],d+things[u][0]);
}
接下来是错误信息。
//RQNOJ:UserCode\547871.cpp: In function `int main()’:
//RQNOJ:UserCode\547871.cpp:14: error: `max’ undeclared (first use this function)
//RQNOJ:UserCode\547871.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)
//RQNOJ:UserCode\547871.cpp: In function `void ah(int, int, int, int)’:
//RQNOJ:UserCode\547871.cpp:21: error: `max’ undeclared (first use this function)
//RQNOJ:UserCode\547871.cpp:26:2: warning: no newline at end of file
求赐教。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询