C/C++ 查找字符串数组中的最小字符串
#include <stdio.h> #include <string.h>
void find(char *s[], int n, int *p) { int min_idx = 0; for (int i = 1; i < n; i++) { if (strcmp(s[i], s[min_idx]) < 0) { min_idx = i; } } *p = min_idx; }
int main() { char *s[100]; int n = 0; while (scanf('%s', s[n]) != EOF) { n++; } int min_idx; find(s, n, &min_idx); printf('%s\n', s[min_idx]); return 0; }
原文地址: http://www.cveoy.top/t/topic/ojJy 著作权归作者所有。请勿转载和采集!