【杭电2015年12月校赛A】【水题 暴力】The Country List 多少个名字与其它名字more than 2位置字符相同

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.
 

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<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)

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值