#include<iostream>using namespace std;int strcomp(char* s, char *t){ int len1 = strlen(s), len2 = strlen(t); for (int i = 0, j = 0; i < len1&&j < len2; ++i){ if (s[i] < t[j]) return -1; else if (s[i]>t[j]) return 1; //相等則不處理 } /* 如果沒從上面for循序的比較中返回,則說明比較的全是相等 此時看長度,長度,相同,則返回 */ if (len1 == len2) return 0; if (len1 < len2) return -1; return 1;}int main(){ char s1[100], s2[100], s3[100], s4[100]; cin >> s1 >> s2 >> s3 >> s4; char mins[100]; strcpy(mins, s1); if (strcomp(mins, s2) > 0) strcpy(mins, s2); if (strcomp(mins, s3) > 0) strcpy(mins, s3); if (strcomp(mins, s4) > 0) strcpy(mins, s4); cout << mins << endl; system("pause");}
#include<iostream>using namespace std;int strcomp(char* s, char *t){ int len1 = strlen(s), len2 = strlen(t); for (int i = 0, j = 0; i < len1&&j < len2; ++i){ if (s[i] < t[j]) return -1; else if (s[i]>t[j]) return 1; //相等則不處理 } /* 如果沒從上面for循序的比較中返回,則說明比較的全是相等 此時看長度,長度,相同,則返回 */ if (len1 == len2) return 0; if (len1 < len2) return -1; return 1;}int main(){ char s1[100], s2[100], s3[100], s4[100]; cin >> s1 >> s2 >> s3 >> s4; char mins[100]; strcpy(mins, s1); if (strcomp(mins, s2) > 0) strcpy(mins, s2); if (strcomp(mins, s3) > 0) strcpy(mins, s3); if (strcomp(mins, s4) > 0) strcpy(mins, s4); cout << mins << endl; system("pause");}