题解 | #比较字符串大小#

比较字符串大小

http://www.nowcoder.com/practice/963e455fdf7c4a4a997160abedc1951b

#include <iostream>
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) {

    // write your code here......
    int cnt=0;
    for(int i=0;src[i]!='\0' or dst[i]!='\0';i++){
        if (src[i] > dst[i]){
            cnt=1;
            break;
        }
        else if (src[i] < dst[i]){
            cnt=-1;
            break;
        }
    }
    return cnt;
    return 0;
    
}
全部评论

相关推荐

醉蟀:你不干有的是人干
点赞 评论 收藏
分享
07-02 10:44
门头沟学院 C++
码农索隆:太实诚了,告诉hr,你能实习至少6个月
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务