3085 - 【创新型】第9章: 指针 9.12 字符串的大小
希望同学们学习完下一章节内容再来做此道题。
--------------------------------------------------------------------
小明想通过自己自己编写实现一个比较字符串大小的函数,即实现strcmp函数。但是他想不出来怎么办,你能帮帮他么(注意不可以用strcmp函数)?
Input
输入两个字符串用空格隔开。
Output
如果第一个字符串大于第二个则输出一个:"字符串1">"字符串2"
反之则输出::"字符串1"<"字符串2"
Examples
Input
shichao jialinpeng
Output
shichao>jialinpeng
Solution C
#include<stdio.h> int Strcmp(char *p1,char *p2); int main() { char a[100],b[100]; int x; scanf("%s %s",a,b); x = Strcmp(a,b); printf("%s",a); if(x>0) printf(">"); else printf("<"); printf("%s",b); } int Strcmp(char *p1,char *p2) { while(*p1 && *p2 && *p1 == *p2) { ++p1; ++p2; } return *p1-*p2; }