明明定义了函数却说找不到?
#include <iostream>using namespace std;
int petrolStation_1(int gas[],int cost[],int N)
{
int k=-1;
int max=0;
for(int i=0;i<N;i++)
{
int sum=0;
int count=0;
for(int j=i;count<N;count++,j=(j+1)%N)
{
if(sum<0) break;
sum+=(gas[j]-cost[j]);
}
if(sum>=max) {k=i;max=sum;}
}
return k;
}
int pertolStation_2(int gas[],int cost[],int N)
{
int *diff=new int[N];
int sum=0;
for(int i=0;i<N;i++)
{
diff[i]=gas[i]-cost[i];
sum+=diff[i];
}
if(sum<0) return -1;
sum=0;
int startNode=0;
for(int i=0;i<N;i++)
{
sum+=diff[i];
if(sum<0)
{
sum=0;
startNode=i+1;
}
}
return startNode;
}
int main()
{
int gas[]={2,0,3,4};
int cost[]={1,2,1,4};
int N=sizeof(gas)/sizeof(gas[0]);
cout<<pertolStation_1(gas,cost,N)<<endl;
cout<<pertolStation_2(gas,cost,N)<<endl;
return 0;
}
E:\codeBlock\加油站\main.cpp|46|error: 'pertolStation_1' was not declared in this scope|
凌乱了,函数定义了啊,为毛说not declared