输入包括多行字符串,字符串的长度len(1<=len<=1000)。
按照原文本中的顺序输出其中最短和最长的字符串,如果最短和最长的字符串不止一个,请全部输出。
hello she sorry he
he hello sorry
#include <stdio.h> ///KY234 最长&最短文本 typedef struct str { char s[1001]; int len; } str; int main() { str a[1001], temp; char x; int t = 0, i, j; while (scanf("%c", &x) != EOF) { i = 0; while (x != '\n') { a[t].s[i] = x; i++; scanf("%c", &x); } a[t].len = strlen(a[t].s); t++; } for (i = 0; i < t; i++) for (j = 0; j < t - 1 - i; j++) if (a[j].len > a[j + 1].len) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } for (i = 0; i < t; i++) { if (a[i].len == a[0].len) printf("%s\n", a[i].s); else if (a[i].len == a[t - 1].len) printf("%s\n", a[i].s); } return 0; }