您的位置:首页 > 理论基础

hdu 计算机学院大学生程序设计竞赛(2015’12)The Country List

2015-12-26 20:54 288 查看


The Country List

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2414 Accepted Submission(s): 559



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.

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.

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 <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
using namespace std;
struct S{
char str[25];
int length;
};
int main()
{
int T;
while(cin>>T)
{
int n=0;
getchar();
S s[105];
for(int i=0;i<T;i++)
{
gets(s[i].str);
s[i].length=strlen(s[i].str);
for(int tt=0;tt<s[i].length;tt++)
if(s[i].str[tt]>='A'&&s[i].str[tt]<='Z')
s[i].str[tt]=(int)s[i].str[tt]+32;
}
for(int i=0;i<T;i++)
{
int flag=1;
for(int j=0;j<T;j++)
{    if(flag!=1) break;
if(i==j) continue;
if(s[i].length==s[j].length)
{
int t=0;
for(int k=0;k<s[i].length;k++)
{
if(s[i].str[k]==s[j].str[k])
t++;
}
if(t>2)
{
flag=0;n++;
}
}
}
}
cout<<n<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: