0
点赞
收藏
分享

微信扫一扫

J - 简单字符串比较

颜路在路上 2022-02-18 阅读 49

Description

请使用字符串比较函数,比较两个字符串的大小,并按要求输出比较后的结果。字符串最长不超过15个字符。
输入两个字符串str1和str2,如果第一个字符串与第二个字符串相等,输出str1=str2,如果第一个字符串大于第二个字符串,输出str1>str2,如果第一个字符串小于第二个字符串,输出str1 < str2。

Input

第1行为第一个字符串。
第2行为第二个字符串。

Output

在一行输出比较后的结果。例如"abc"与"abc"相等,输出为abc=abc,如果"ab"小于"abc”,输出ab < abc。

Sample

Input 

ab
abc

Output 

ab<abc

Hint

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(){
    char str1[16];
    char str2[16];
    int a;
    scanf("%s %s", str1, str2);
    a = strcmp(str1, str2);
    if(a > 0){
        printf("%s>%s\n", str1, str2);
    }
    else if(a == 0){
        printf("%s=%s\n", str1, str2);
    }
    else{
        printf("%s<%s\n", str1, str2);
    }

    return 0;
}

举报

相关推荐

0 条评论