https://www.acmicpc.net/problem/1316
코드 #1
#include<stdio.h>
int getLength(char * array);
int compare(char * array, int length);
int main() {
int n=0;
int length = 0;
int cnt = 0;
char array[100] = {0};
scanf("%d", &n);
for(int i=0; i<n; i++) {
scanf("%s", array);
length = getLength(array);
cnt += compare(array, length);
}
printf("%d", cnt);
}
int getLength(char * array) {
int length = 0;
while(array[length] != 0) {
length++;
}
return length;
}
int comapre(char * array, int length) {
for(int i=0; i<length; i++) {
for(int j=i; j<length; j++) {
if(array[i] == array[j]) {
if(j-i > 1) {
return 0;
}
}
}
}
return 1;
}
오류 메시지
prog.c: In function ‘main’:
prog.c:13:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^~~~~~~~~~~~~~~
prog.c:15:9: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", array);
^~~~~~~~~~~~~~~~~~
/usr/bin/ld: /home/fq5FRC/ccVeYioD.o: in function `main':
prog.c:(.text.startup+0xa4): undefined reference to `compare'
collect2: error: ld returned 1 exit status
코드 #2
#include<stdio.h>
int main(void) {
int N = 0;
char input_words[101];
scanf("%d", &N);
int count = N;
for(int i=0; i<N; i++) {
int alphabet[26] = {0, };
char first = '0';
scanf("%s", input_words);
for(int j=0; input_words[j] != '\0'; j++) {
if(first != input_words[j]) {
first = input_words[j];
alphabet[input_words[j] - 'a']++;
}
if(alphabet[input_words[j] - 'a'] == 2) {
count--;
break;
}
}
}
printf("%d", count);
return 0;
}