zoukankan      html  css  js  c++  java
  • HDU计算机学院大学生程序设计竞赛(2015’12)The Country List

    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;
    }
    

      

     
     
  • 相关阅读:
    #背包方案 ——整数划分(Acwing900)
    #分组背包 #背包方案 ——Acwing 1013 机器分配
    #背包 #二进制优化 ——Acwing 5. 多重背包问题 II(二进制优化)
    #背包方案 AcWing 532. 货币系统
    #背包方案 ——AcWing 1021. 货币系统2
    背包问题求方案数
    有依赖的背包问题
    分组背包问题
    二维费用的背包问题
    混合背包问题
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5087064.html
Copyright © 2011-2022 走看看