编写一个程序,该程序读取不超过 1000 个字符串,每个字符串最多包含 99 个字符,并以输入流中的 NEWLINE 字符结尾。然后,打印出所有字谜集,每组只能打印一次。在每个打印集中,字符串必须按输入顺序显示。
字谜集:如果一个字符串包含相同(且至少一个)的字母和数字,则称为另一个字符串的字谜,可能采用不同的顺序,忽略大小写。请注意,根据此定义,将忽略所有非字母数字字符。例如,“1a2”,“1a2,-+”,“A21”都是“2 + 1 = a”的字谜,但“1aa2”不是。
example:input:
a bc
a12+-
1a2
1a +-
Cab
z
ccab
例子output:
#set 1:
a bc
Cab
#set 2:
a12+-
1a2
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_STRS 1000
#define MAX_STR_LEN 99
#define NUM_LETTERS 26
#define NUM_DIGITS 10
#define SIZE (NUM_LETTERS + NUM_DIGITS)
int read_strings(char ss[][MAX_STR_LEN + 1]);
int is_anagram(char *s1, char *s2);
int main(int argc, char *argv[]) {
return 0;
}
int read_strings(char ss[][MAX_STR_LEN + 1]) {
int n = 0;
printf("Enter strings (max=%d characters each):\n", MAX_STR_LEN);
for ( ; n < MAX_STRS && scanf(" %[^\n]", ss[n]) == 1; n++);
return n;
}
/*
returns 1 if the two strings contain the same letters & digits,
possibly in a different order, and 0 otherwise,
ignoring whitespace characters, and ignoring case
in addition, ignoring any non-alphanumeric characters,
*/
int is_anagram(char *s1, char *s2) {
}