hdu 计算机学院大学生程序设计竞赛(2015’12)The Country List
2015-12-26 20:54
288 查看
The Country List
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2414 Accepted Submission(s): 559
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
#include <iostream> #include <stdio.h> #include <string> #include <cstring> using namespace std; struct S{ char str[25]; int length; }; int main() { int T; while(cin>>T) { int n=0; getchar(); S s[105]; for(int i=0;i<T;i++) { gets(s[i].str); s[i].length=strlen(s[i].str); for(int tt=0;tt<s[i].length;tt++) if(s[i].str[tt]>='A'&&s[i].str[tt]<='Z') s[i].str[tt]=(int)s[i].str[tt]+32; } for(int i=0;i<T;i++) { int flag=1; for(int j=0;j<T;j++) { if(flag!=1) break; if(i==j) continue; if(s[i].length==s[j].length) { int t=0; for(int k=0;k<s[i].length;k++) { if(s[i].str[k]==s[j].str[k]) t++; } if(t>2) { flag=0;n++; } } } } cout<<n<<endl; } return 0; }
相关文章推荐
- 国内外研究主页集合:计算机视觉-机器学习-模式识别
- Java网络编程(1) Socket缓…
- CMake安装和使用 http://blog.sina.com.cn/s/blog_5aee9eaf0100y36u.html
- Python 网络编程 SocketServer
- cas入门:https形式发布cas证书制作
- CMake 使用方法 http://www.cnblogs.com/lyq105/archive/2010/12/03/1895067.html
- 算法设计题2.30-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- Python 网络编程 Socket
- 网络流24题 之十四 孤岛营救问题 分层图
- 算法设计题2.29-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- TCP简介
- AsyncHttpClient
- 算法设计题2.28-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- 算法设计题2.27-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- 算法设计题2.26-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- 算法设计题2.25-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版
- linux内核ipv4网络部分分层结构及涉入源文件
- 使用HTTP访问网络
- DS-SDOJ-数据结构实验之排序三:bucket sort
- 算法设计题2.24-线性表-第2章-《数据结构习题集》-严蔚敏吴伟民版