#include
using namespace std;
int Diff(char *str1, char *str2)
{
char *head1 = str1;
char *head2 = str2;
while(true)
{
if(*head1 != *head2)
return (*head1 > *head2) ? (*head1 - *head2) : (*head2 - *head1);
else
{
head1++;
head2++;
if(*head1 == '\0' && *head2 != '\0')
return *head2;
else if(*head2 == '\0' && *head1 != '\0')
return *head1;
else if(*head1 == '\0' && *head2 == '\0')
break;
}
}
return 0;
}
void main()
{
char *str1 = "abc";
char *str2 = "abcdfdgf";
cout<}
随手写的,没有测过,是个大概思路。
DurantSimpson的回答有问题,
“abc”和“abcd”打印结果是0
“abce”和“abcd”打印结果是-1
#include
#include
main()
{
char str1[100],str2[100];
int i=0,flag=0;
printf("enter the first string\n");
scanf("%s",str1);
printf("enter the second string\n");
scanf("%s",str2);
while(str1[i]!='\0' && str2[i]!='\0')
{
if( str1[i]!= str2[i] ){
flag = 1;
break;
}else
i++;
}
if(flag == 1)
printf("%d\n",str2[i]-str1[i]);
else
printf("%d\n",0);
}
如何编程实现:...
--首先要选定,用什么语言来编这个程序。