请教strcmp函数的用法!
爷们姓邱 2011-12-18 11:44:30 C++新手 望指教!
USACO上的题 c++ 提交上之后提示::
Compiling...
Compile error: your program did not compile correctly:
program.c: In function 'int main()':
program.c:29:26: error: 'strcmp' was not declared in this scope
--> 28: for(j=0;j<num;j++)
--> 29: if(0!=strcmp(a,name[j]))
program.c:39:25: error: 'strcmp' was not declared in this scope
--> 38: for(k=0;k<num;k++)
--> 39: if(!strcmp(a,name[j]))
Compile errors; end of this run.
下面d我的码:
/*
ID:qiushil3
PROG:gift1
LANG:C++
*/
#include<fstream>
#include<string>
using namespace std;
int main(void)
{
int num;
char a[20];
char name[20][20];
int money[20],mymoney[20];
int i,j,k,tt,mny,nn;
ofstream fout ("gift1.out");
ifstream fin ("gift1.in");
fin >> num;
for(i=0;i<num;i++)
{
fin >> name[i];
money[i]=0;
mymoney[i]=0;
}
for(i=0;i<num;i++)
{
fin >> a;
for(j=0;j<num;j++)
if(!strcmp(a,name[j]))
{
tt=j;//tt: number of the money's owner
break;
}
fin >> mny >> nn;
mny/=nn;
mymoney[tt]=mny*nn;
for(j=0;j<nn;j++)
for(k=0;k<num;k++)
if(!strcmp(a,name[j]))
money[j]+=mny;
}
//Output below this line
for(i=0;i<num;i++)
{
fout << name[i] << " ";
fout << money[i]-mymoney[i] << endl;
}
return 0;
}