Dave is the director of the Summer school of hot air ballooning. Being a responsible director,
he keeps a list of flights of each trainee in the school. After each flight, Dave appends a note
to the lists of flights of each trainee participating in that particular flight. The note is very
simple, it just indicates the type number of the balloon. In this way, each trainee flight history
is characterized by a list of numbers.
At the end of the season, Dave wants to categorize the trainees according to their experience
with different brands of balloons.
Two trainees belong to the same category if they have flown the same types of balloons. It does
not matter how many times they have flown any particular balloon type, what does matter is
the set of the balloon types they have flown and that has to be the same.
There are exactly nine types of balloons in Dave’s school, and no trainee has flown more than
nine times in a balloon, so Dave expresses each trainee list as an integer consisting of digits
1,2,…,9 and smaller than one billion. He thinks that this representation will help him to
process the lists programmatically by a computer.
For example, the trainees characterized by integers 234423 and 342 belong to the same category,
while the trainees characterized by integers 118821 and 1189821 belong to different categories.
Help Dave to calculate how many different categories of trainees attended the school this season.
Input Specification
There are more test cases. Each case starts with a line containing one integer N (1 ≤ N ≤ 1000)
representing the number of trainees. Next, there are N lines, each line contains one integer
representing the list of flights of one particular trainee.
Output Specification
For each test case, print a single line with one integer C specifying the number of different
trainee categories in the school.
Sample Input
5
132
42
3312
43
24424
3
222
22
2
Output for Sample Input
3
1
题意:这个题的意思就是说每个飞行员的驾驶的热气球编号为1-9,每驾驶一次就记下一个编号
当他们的热气球所含编号相同的时候为同一类如2444和24,都只含有2,4就是一类飞行员。问总共有几类飞行员。因为总共有9个数,这个题使用的方法就是标记下第几个数出现过,如果再次出现并已经标记就不在操作,每一个字符串都与其他字符串比较,如果标记的位置都相同就是同一类飞行员。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char s[10],type[1100][11],t1[11],t2[11];
int main()
{
int i,j,k,n;
while(~scanf("%d",&n))
{
memset(type,'n',sizeof(type));//江整个字符串初始化成n;
int count=0;
for(i=0;i<n;i++)
{
scanf("%s",s);
int len = strlen(s);
k=0;
for(j=0;j<len;j++)
{
int x = s[j] - '0';
if(type[i][x] == 'n')
{
type[i][x] = 'y';//如果该位置上的数字没有标记过就标记下来,如果已经标记过就不做处理。
k++;
if(k == 10)//总共有九个数,超过十的数不计算。
break;
}
}
type[i][10] = '\0';
}
for(i=0;i<n;i++)
{
if(strcmp(type[i],"nnnnnnnnnn")==0)
continue ;
strcpy(t1,type[i]);
for(j=i+1;j<n;j++)
{
strcpy(t2,type[j]);
if(strcmp(t1,t2) == 0)
strcpy(type[j],"nnnnnnnnnn");
}
count++;
}
printf("%d\n",count);
}
return 0;
}