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

来源:互联网 发布:广联达定额计价软件 编辑:程序博客网 时间:2024/06/06 18:21

The Country List

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2516    Accepted Submission(s): 592


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 <cstring>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <queue>#include <stack>#include <set>#include <map>#include <list>#define LL long long#define INF 0x3f3f3f3fusing namespace std;char s[110][25];int len[110];int main(){    int n;    while(~scanf("%d",&n))    {        int ant = 0;        for(int i=0; i<n; i++)            scanf("%s",s[i]), len[i] = strlen(s[i]);        for(int i=0; i<n; i++)        {            for(int j=0; j<n; j++)            {                if(i!=j)                {                    if(len[i] == len[j])                    {                        int num = 0;                        for(int k = 0; k < len[j]; k++)                        {                            if(s[i][k] == s[j][k] || s[i][k] == s[j][k] + 32 ||s[i][k] == s[j][k] - 32)                                num++;                        }                        if(num >2)                        {                            ant++;                            break;                        }                    }                }            }        }        cout<<ant<<endl;    }    return 0;}


0 0
原创粉丝点击