题目要求如下:
输入2个字符串,比较两个字符串之间的长度,如果长度相同则输出长度相等。反之,输出长度小于或大于。
主要可以通过strlen进行字符串之间长度的比较。
下面是实现的代码
#include <stdio.h>
#include <string.h>
int main() {
int n;
while (scanf("%d", &n) != EOF) {
char s1[51] = {0};
char s2[51] = {0};
for (int i = 0; i < n; ++i) {
scanf("%s", s1);
int a = strlen(s1);
scanf("%s", s2);
int b = strlen(s2);
if (a == b) {
printf("%s is equal long to %s\n", s1, s2);
} else if (a < b) {
printf("%s is shorter than %s\n", s1, s2);
} else {
printf("%s is longer than %s\n", s1, s2);
}
}
}
return 0;
}
最终通过后的结果: