代码
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char command[255];
scanf("%[^\n]", command);//与gets同效果 输入换行符停止输入
int len = strlen(command);
int i, j;
char options[26] = {0}; // 用一个数组来表示26个小写字母,出现过的选项置为1
for (i = 0; i < len; i++) {
if (command[i] == '-') { // 如果遇到减号,找到紧跟的字母并将对应的数组值置为1
if (islower(command[i + 1])) {
options[command[i + 1] - 'a'] = 1;
}
}
}
int flag = 0; // 用来标记是否有选项出现
for (i = 0; i < 26; i++) {
if (options[i] == 1) {
printf("-%c ", 'a' + i);
flag = 1;
}
}
if (flag == 0) {
printf("no\n");
}
return 0;
}