函数题:字符串比较
要求实现一个字符串比较函数strcmp,函数原型为“int strcmp(char* s,char* t);”,其中s指向字符串s1,t指向字符串s2,要求当s1等于s2时,函数返回值为0,若s1≠s2,则返回二者中第一个不相同字符的ASCII码差值(如"BOY"与"BAD"的第二个字母不同,'O'与'A'之差为79-65=14)。
### 函数接口定义:
c++
int strcmp(char* s,char* t);
其中 s 和 t 是用户传入的两个指针参数,用于指向两个实参字符数组。
### 裁判测试程序样例:
c++
#include <iostream>
using namespace std;
int strcmp(char* s,char* t);
const int N=11;
int main() {
char s1[N], s2[N];
while(cin>>s1>>s2){
cout<<strcmp(s1, s2)<<endl;
}
return 0;
}
### 输入样例:
in
abc Abd
abcAd abca
abc abc
### 输出样例:
out
32
-32
0
答案:若无答案欢迎评论
### 函数接口定义:
c++
int strcmp(char* s,char* t);
其中 s 和 t 是用户传入的两个指针参数,用于指向两个实参字符数组。
### 裁判测试程序样例:
c++
#include <iostream>
using namespace std;
int strcmp(char* s,char* t);
const int N=11;
int main() {
char s1[N], s2[N];
while(cin>>s1>>s2){
cout<<strcmp(s1, s2)<<endl;
}
return 0;
}
### 输入样例:
in
abc Abd
abcAd abca
abc abc
### 输出样例:
out
32
-32
0
答案:若无答案欢迎评论