6-20 strcmp (30分)

6-20 strcmp (30分)
 

Implement the strcmp() as in the standard library.

函数接口定义:

int mycmp( const char* s1, const char* s2 );
 

returns 0 when s1 equals to s2, otherwise returns the distance between s1 and s2.

裁判测试程序样例:

#include <stdio.h>

int mycmp( const char* s1, const char* s2 );

int main()
{

  char s1[80], s2[80];

  scanf("%s %s", s1, s2);

  printf("%d", mycmp(s1,s2));

  return 0;

}

/* 请在这里填写答案 */
@@@
 

输入样例:

hello hello
 

输出样例:

0



1 int mycmp( const char* s1, const char* s2 )
2 {
3     while(*s1&&*s2&&*s1==*s2)s1++,s2++;
4     return *s1-*s2;
5 }

 

 
posted @ 2020-10-19 20:28  罪梦者  阅读(175)  评论(0)    收藏  举报