Programming/c
[2**] N๊ฐ์ ๋จ์ด๋ฅผ ํฌํจํ๋ ๋ฌธ์์ด A๋ฅผ ์ ๋ ฅ๋ฐ๊ณ ๋ฌธ์์ด์์ ์ค๋ณต๋ ๋จ์ด 1๊ฐ๋ฅผ ์ฐพ์ ํ๋ฉด์ ์ถ๋ ฅ
ํด๋์๊ทธ
2021. 5. 16. 01:44
๋ฐ์ํ
์ ๋ ฅ ์์ 1 ์ถ๋ ฅ ์์ 1
red orange yellow green orange orange โฆ ๋ฌธ์์ด์์ ์ค๋ณต๋ ๋จ์ด๋ orange์ด๋ค. ์ ๋ ฅ ์์ 2 ์ถ๋ ฅ ์์ 2 pink red yellow black yellow purple yellow
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int i = 0, cnt = 0, t = 0;
char A[101], str[20][101];
gets(A);
int k = 0, s = 0;
while (A[i] != '\0') {
if (A[i] != ' ' && A[i]!='\0') {
str[k][s] = A[i];
s++;
}
else {
str[k][s] = '\0';
k++;
s = 0;
}
i++;
}
str[k][s] = '\0';
k++;
for (int j = 0; j < k; j++) {
for (int m = j+1; m < k; m++) {
if (strcmp(str[j], str[m]) == 0) {
t = j;
}
}
}
printf("%s", str[t]);
}
๋ฐ์ํ