程序代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> void word(char *s1, char *s2) { puts("Input 1st word:"); scanf("%80[a-zA-Z]", s1); while(getchar() != '\n') continue; puts("Input 2nd word:"); scanf("%80[a-zA-Z]", s2); if(strlen(s1) != strlen(s2)) { printf("No!\n"); exit(EXIT_FAILURE); } } int cmp(const char *s1, const char *s2) { int a[80] = {0}, b[80] = {0}; int i, j, flag = 0; for(i = 0; s1[i] != '\0' && i < 80; i++) { if(s1[i] >= 97) a[i] = s1[i]; else a[i] = s1[i] + 32; if(s2[i] >= 97) b[i] = s2[i]; else b[i] = s2[i] + 32; } for(i = 0; a[i] && i < 80; i++) { for(j = 0; j < 80; j++) { if(a[i] == b[j]) { b[j] = 0; break; } } } for(i = 0; i < 80; i++) flag += b[i]; return flag; } int main(void) { char s1[81] = {0}, s2[81] = {0}; word(s1, s2); if(cmp(s1, s2)) printf("No!!\n"); else printf("Yes...\n"); return 0; }
[ 本帖最后由 longwu9t 于 2015-3-24 20:41 编辑 ]
Only the Code Tells the Truth K.I.S.S