C代码1:
bool isAcronym(char ** words, int wordsSize, char * s){
if (wordsSize != strlen(s)) {
return false;
}
for (int i = 0; i < wordsSize; ++i) { // 遍历所有,没有不满足的就是满足的
if (words[i][0] != s[i]) {
return false;
}
}
return true;
}
C代码2:
bool isAcronym(char ** words, int wordsSize, char * s){
char* str = (char*)malloc(sizeof(char) * 101);
int strTop = 0;
for (int i = 0; i < wordsSize; ++i) {
str[strTop++] = words[i][0];
}
str[strTop] = '\0';
return strcmp(str, s) == 0;
}