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

比较字符串大小

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......
    while((*src)!='\0'&&(*dst)!='\0'){
        if((*src)==(*dst)){
            src++;
            dst++;
        }else if((*src)>(*dst)){
            return 1;
        }else{
            return -1;
        }
    }
    if((*src)!='\0'&&(*dst)!='\0') return 0;
    if((*src)!='\0') return 1;
    if((*dst)!='\0') return -1;
    return 0;
}
全部评论
Line 34错了
点赞 回复 分享
发布于 2024-05-21 20:21 陕西

相关推荐

面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
10
1
分享

创作者周榜

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