mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
40 lines
725 B
Markdown
40 lines
725 B
Markdown
|
# 6-5 字符串比较
|
|||
|
|
|||
|
函数fun的功能是比较两个字符串,如果s1=s2,则返回值0;如果s1>s2,则返回值1;如果s1<s2,则返回-1。
|
|||
|
|
|||
|
### 函数接口定义:
|
|||
|
```c++
|
|||
|
int fun(char a[],char b[]);
|
|||
|
```
|
|||
|
|
|||
|
其中`a`、`b`是用户传入的参数。 函数比较两个字符串,如果`a`=`b`,则返回值0;如果`a`>`b`,则返回值1;如果`a`<`b`,则返回-1。
|
|||
|
|
|||
|
### 裁判测试程序样例:
|
|||
|
```c++
|
|||
|
#include "stdio.h"
|
|||
|
#include "string.h"
|
|||
|
int fun(char a[],char b[]);
|
|||
|
int main()
|
|||
|
{int t;
|
|||
|
char s1[40],s2[40];
|
|||
|
gets(s1); gets(s2);
|
|||
|
t=fun(s1,s2);
|
|||
|
printf("%d\n",t);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/* 请在这里填写答案 */
|
|||
|
```
|
|||
|
|
|||
|
### 输入样例:
|
|||
|
```in
|
|||
|
asd
|
|||
|
fg
|
|||
|
```
|
|||
|
|
|||
|
### 输出样例:
|
|||
|
```out
|
|||
|
-1
|
|||
|
```
|