The Country List(杭电12月比赛)

来源:互联网 发布:云计算 校园招聘 编辑:程序博客网 时间:2024/06/16 13:13

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
3DenmarkGERMANYChina4AaaaaBaacBaacBad
 

Sample Output
24
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;//每次只比较一次,如果一个单词和下面的几个一样时。注意每个单词只比较一次//如果分不清就 跳到下一个单词比较int main(){    int n;    char dc[105][25];    int len[105]={0};    while(cin>>n)    {        for(int i=0;i<n;i++)        {            scanf("%s",dc[i]);            len[i]=strlen(dc[i]);            for(int k=0;k<len[i];k++)                dc[i][k]=tolower(dc[i][k]);        }        int ans=0;        for(int i=0;i<n;i++)        {            int flag=0;            for(int j=0;j<n;j++)            {                if(len[i]==len[j]&&i!=j)                {                    int temp=0;                    for(int k=0;k<len[i];k++)                    {                        if(dc[i][k]==dc[j][k])                            temp++;                        if(temp>2)                        {                            flag=1;                            break;                        }                    }                    if(flag)break;                }            }            ans+=flag;        }        cout<<ans<<endl;    }    return 0;}

0 0
原创粉丝点击