2015'12杭电新生赛1001 The Country List

本文探讨了在处理相似国家名称识别的问题上,通过比较国家名称的长度和相同位置字母的数量来判断是否难以区分,提供了识别无法区分国家名称数量的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题解:

水题不解释

代码

#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <bitset>
#define MAX 100000
#define LL long long
using namespace std;
int cas=1,T,n;
char word[110][30];
int cmp(int x,int y)
{
    int sum=0;
    for(int i=0;word[x][i]&&word[y][i];i++)
        if(tolower(word[x][i])==tolower(word[y][i])) 
            sum++;
    return sum;
}
int vis[110];

int main()
{
    //freopen("in","r",stdin);
    //scanf("%d",&T);
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++) 
            scanf("%s",word[i]);
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
            {
                if(strlen(word[i])==strlen(word[j])&&cmp(i,j)>2) 
                    vis[i]=vis[j]=1;
            }
        int countt=0;
        for(int i=0;i<n;i++) if(vis[i]) countt++;
        printf("%d\n",countt);
    }
    return 0;
}

题目

The Country List

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值