题解 | #比较字符串大小#
比较字符串大小
https://www.nowcoder.com/practice/963e455fdf7c4a4a997160abedc1951b
#include <iostream> #include <string.h>//插入一个新的头文件 using namespace std; int mystrcmp(const char* src, const char* dst); int main() { char s1[100] = { 0 }; char s2[100] = { 0 }; cin.getline(s1, sizeof(s1)); cin.getline(s2, sizeof(s2)); int ret = mystrcmp(s1, s2); cout << ret << endl; return 0; } int mystrcmp(const char* src, const char* dst) { int res; // write your code here...... int result=strcmp(src,dst);//调用strcmp函数就可以了 if (result>0) res= 1; else if(result<0) res=-1; else res=0; return res; }