The Country List
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2558 Accepted Submission(s): 603
Problem Description
As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable to be a volunteer of such an international pageant. His job is to guide the foreign visitors. Although he has a strong desire to be an excellent volunteer, the lack of English makes him annoyed for a long time.
Some countries’ names look so similar that he can’t distinguish them. Such as: Albania and Algeria. If two countries’ names have the same length and there are more than 2 same letters in the same position of each word, CC cannot distinguish them. For example: Albania and AlgerIa have the same length 7, and their first, second, sixth and seventh letters are same. So CC can’t distinguish them.
Now he has received a name list of countries, please tell him how many words he cannot distinguish. Note that comparisons between letters are case-insensitive.
Some countries’ names look so similar that he can’t distinguish them. Such as: Albania and Algeria. If two countries’ names have the same length and there are more than 2 same letters in the same position of each word, CC cannot distinguish them. For example: Albania and AlgerIa have the same length 7, and their first, second, sixth and seventh letters are same. So CC can’t distinguish them.
Now he has received a name list of countries, please tell him how many words he cannot distinguish. Note that comparisons between letters are case-insensitive.
Input
There are multiple test cases.
Each case begins with an integer n (0 < n < 100) indicating the number of countries in the list.
The next n lines each contain a country’s name consisted by ‘a’ ~ ‘z’ or ‘A’ ~ ‘Z’.
Length of each word will not exceed 20.
You can assume that no name will show up twice in the list.
Each case begins with an integer n (0 < n < 100) indicating the number of countries in the list.
The next n lines each contain a country’s name consisted by ‘a’ ~ ‘z’ or ‘A’ ~ ‘Z’.
Length of each word will not exceed 20.
You can assume that no name will show up twice in the list.
Output
For each case, output the number of hard names in CC’s list.
Sample Input
3 Denmark GERMANY China 4 Aaaa aBaa cBaa cBad
Sample Output
2 4
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int casenum,casei;
typedef long long LL;
int n;
char s[105][24];
int l[105];
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;++i)
{
scanf("%s",s[i]);
l[i]=strlen(s[i]);
for(int j=0;j<l[i];++j)s[i][j]=tolower(s[i][j]);
}
int ans=0;
for(int i=1;i<=n;++i)
{
bool flag=0;
for(int j=1;j<=n;++j)if(j!=i&&l[i]==l[j])
{
int num=0;
for(int k=0;k<l[i];++k)
{
if(s[i][k]==s[j][k])++num;
if(num>2){flag=1;break;}
}
if(flag)break;
}
ans+=flag;
}
printf("%d\n",ans);
}
return 0;
}
/*
【题意】
给你n(100)个字符串,每个字符串的长度不超过20。
对于一个字符串,如果存在另外一个字符串,与其长度相同,且有more than 2 same letters in ther same position of each word.
(Case Insensitive)
那么这个字符串就被认定为cannot distinguish
问你,在这n个字符串中,有多少个cannot distinguish
【类型】
暴力
【分析】
只要暴力O(n^2 * len)统计一下即可。
不过要小心——
1,细节不要写错(我竟然在这题wa了一次,好蠢!)
2,是more than 2
【时间复杂度&&优化】
O(n^2 * len)
*/