in:2
5 red blue red yellow yellow
3 red yellow blue
out:
3
blue red yellow
3
blue red yellow
#include <stdio.h>
#include <string.h>
int main()
{
int T;
char color[100][11] = {0};
char buf[11];
scanf("%d", &T);
while (T--)
{
int n;
scanf("%d", &n);
int cnt = 0, nohas;
for (int i = 0; i < n; i++)
{
nohas = 1;
scanf("%s", buf);
for (int j = 0; j < i; j++)
{
if (strcmp(buf, color[j]) == 0)
{
nohas = 0;
break;
}
}
if (nohas)
{
strcpy(color[cnt], buf);
cnt++;
}
}
printf("%d\n", cnt);
for (int i = 0; i < cnt - 1; i++)
{
for (int j = i+1; j < cnt; j++)
{
if(strcmp(color[i],color[j])>0)
{
strcpy(buf, color[i]);
strcpy(color[i], color[j]);
strcpy(color[j], buf);
}
}
}
for (int i = 0; i < cnt; i++)
{
printf("%s ", color[i]);
}
printf("\n");
}
return 0;
}