如何设计两个串比较的程序,程序中不使用加、减,当串相等时返回0,大于时返回1,小于时返回-1?

来源:百度知道 编辑:UC知道 时间:2024/06/21 16:37:18

#include<iostream.h>
#include<string>
int BJ(string a,string b)
{
if(a.length()>b.length())
{
return 1;
}
if(a.length()==b.length())
{
return 0;
}
if(a.length()<b.length())
{
return -1;
}
}

void main()
{
string a;
string b;
cout<<"enter two word:";
cin>>a;
cin>>b;
int c;
c=BJ(a,b);
cout<<c<<endl;

}

你想用什么语言来做呢?

用C语言的话直接就有这样的函数了,你只要拿来用就行了