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

The Country List

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

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

查找单词是否相同(相同的条件 长度相同,且有三个相同位置以上的有相同字母)

用set存一存就好了

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int n;
string ss[100];
set<string> q;
int main ()
{
    while(cin>>n)
    {
        int i,j;
        for(i=0; i<n; i++)
        {
            cin>>ss[i];
        }
        for(i=0; i<n; i++)
        {
            for(j=0; j<n; j++)
            {
                int sum=0;
                if(i==j) continue;
                if(ss[i].length()==ss[j].length())
                {
                    for(int z=0; z<ss[i].length(); z++)
                    {
                        if(ss[i][z]==ss[j][z]||abs(ss[i][z]-ss[j][z])==32)
                        {
                            sum++;
                        }
                    }
                    if(sum>2)
                    {
                  //      cout<<ss[i]<<" "<<ss[j]<<endl;
                        q.insert(ss[j]);
                    }
                }

            }
        }
        cout<<q.size()<<endl;
        q.clear();
    }
    return 0;
}

  

时间: 2024-08-01 20:16:22

HDU计算机学院大学生程序设计竞赛(2015’12)The Country List的相关文章

hdu 计算机学院大学生程序设计竞赛(2015’11)

搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5134    Accepted Submission(s): 1288 Problem Description 小明现在是人见人爱,花见花开的高富帅,整天沉浸在美女环绕的笙歌妙舞当中.但是人们有所不知,春风得意的小明也曾有着一段艰苦的奋斗史. 那时的小明还没剪去长发,没有信用卡没有她

HDU计算机学院大学生程序设计竞赛(2015’12)Happy Value

Happy Value Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1453    Accepted Submission(s): 428 Problem Description In an apartment, there are N residents. The Internet Service Provider (ISP) wa

HDU计算机学院大学生程序设计竞赛(2015’12)1008 Study Words

题意: 输入一篇文章,输出出现最多的10个单词 不包括old里的已有单词 出现次数相同按字典序大小 简单模拟,map记录个数 没有什么坑点 然后sort一下 用string 可以直接比较字典序大小 #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorithm> #include<map> #include<mat

HDU计算机学院大学生程序设计竞赛(2015’12)1005 Bitwise Equations

题意:已知x,k 求第k个使得x+y==x|y的正整数y x+y==x|y 即x为1的位y为0 可知y有几位可以为1 详见代码 #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorithm> #include<map> using namespace std; const int N=50005; int n,k; i

HDU计算机学院大学生程序设计竞赛(2015’12)1003 The collector’s puzzle

题意: 有N个珠宝 M个箱子 珠宝价值a  箱子价值b 每个珠宝放在箱子里,花费abs(a-b) 箱子可以无限放珠宝 求最小花费 水题 预处理每个价值的珠宝所放的箱子O(n) 从左往右找到最接近的左箱子l  从右往左找到最接近的右箱子r 取min #include<cstdio> #include<cstring> #include<string> #include<iostream> #include<algorithm> #include&l

HDU计算机学院大学生程序设计竞赛(2015’12)1006 01 Matrix

题意: 有一个n*n(n<=1000)的01矩阵 Q次询问(1000) 每次询问有几个大于等于k的全为一的子矩形 从右下角往右上角预处理每个点有一个r x vr代表右边有多少连续1x代表下面有多少连续1v代表以这个为左上角的矩阵最大是多少所以v[i][j]= min(r[i][j+1], x[i+1][j],v[i+1][j+1]) +1 r[i][j]=r[i][j+1]+1; x[i][j]=x[i+1][j]+1; 然后ans[v[i][j]]++ 预处理后缀和  O 1 输出 #incl

计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

Problem Description There is a collector who own many valuable jewels. He has a problem about how to store them. There are M special boxes. Each box has a value. And each of the N jewels has a value too. The collector wants to store every jewel in on

计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

#include<cstdio> #include<algorithm> using namespace std; using namespace std; const int maxn=100000+10; int a[maxn],b[maxn]; int main() { int n,m; while(scanf("%d %d",&n,&m)!=EOF) { for(int i=1; i<=n; i++) scanf("%d&

计算机学院大学生程序设计竞赛(2015’12) 1002 Polygon

#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; struct Point { double x; double y; } p[1001], px[10001]; int n; double eps=1e-8; int cmp(Point a, Point b) { if(ab