题目链接:http://poj.org/problem?id=4054

本题的题意是在下面那部分待检验的单词中找到与之相对应的正确的代词,包含几种情况,一是全部字母相同,二是有一个字母不相同,三是多一个字母,四是少一个字母。

解本道题目:首先把错误的情况分为三种

1.字母数相同

2.待检验的单词的字母数比正确的单词的字母数多一

3.待检验的单词的字母数比正确的单词的字母数少一

然后注意一下细节;找到前面三种类型的单词,不要急着将单词输出,将这些单词保存在另外一个数组里面,如果遇到正确的单词,直接输出is correct,否则输出数组里面的字符串

代码如下:

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char dic[][],che[][];
char res[][];
char temp[];
int flag;
int num;
int main(){
int len1=,len2=;
bool flag;
while(){
cin>>dic[len1];
if(dic[len1][]=='#'){
break;
}
len1++;
}
while(){
cin>>che[len2];
if(che[len2][]=='#'){
break;
}
len2++;
}
for(int i=;i<len2;i++){
int len4=strlen(che[i]);
flag=;
num=;
for(int k=;k<;k++){
for(int j=;j<;j++){
res[k][j]='\0';
}
}
for(int j=;j<len1;j++){
int len3=strlen(dic[j]);
if(len3==len4){ //字符串长度相等的情况
if(strcmp(che[i],dic[j])==){
printf("%s is correct",dic[j]);
flag=;
break;
}
else{
int sum=;
for(int k=;k<len3;k++){
if(che[i][k]!=dic[j][k]){
sum++;
}
}
if(sum==){
strcpy(res[num],dic[j]);
num++;
}
}
}
else if(len3==len4+){ //字典里面的单词比待检验的单词的数量多一
for(int k=;k<len3;k++){
strcpy(temp,dic[j]);
for(int h=k;h<len3;h++){
temp[h]=temp[h+];
}
if(strcmp(temp,che[i])==){
strcpy(res[num],dic[j]);
num++;
break;
}
}
}
else if(len4==len3+){ //待检验的单词比字典里面的字母数多一
for(int k=;k<len4;k++){
strcpy(temp,che[i]);
for(int h=k;h<len4;h++){
temp[h]=temp[h+];
}
if(strcmp(temp,dic[j])==){
strcpy(res[num],dic[j]);
num++;
break;
}
}
}
}
if(flag==){
// cout<<num<<endl<<endl;
printf("%s: ",che[i]);
for(int j=;j<num;j++){
printf("%s ",res[j]);
// cout<<a++<<endl;
}
}
printf("\n");
}
return ;
}

poj 1035KINA Is Not Abbreviation的更多相关文章

  1. OpenJudge/Poj 2001 Shortest Prefixes

    1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...

  2. poj 2001 Shortest Prefixes(特里)

    主题链接:http://poj.org/problem?id=2001 Description A prefix of a string is a substring starting at the ...

  3. POJ 2001 Shortest Prefixes (Trie)

    题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...

  4. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  5. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  6. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  7. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  8. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  9. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

随机推荐

  1. Ignatius and the Princess II

    Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  2. 最长上升子序列(logN算法)

    例如:1 7 3 5 9 4 8 一个序列,比如说a[]={1,7,3,5,9,4,8},找出它的最长上升子序列的个数,很明显是4个,可以是{1,3,5,9},{1,3,5,8}或者{1,3,4,8} ...

  3. hdu 2089 不要62(入门数位dp)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. 路由知识 静态路由 rip eigrp ospf

    第1章 路由选择原理 1.1 几个概念 1.1.1 被动路由协议 用来在路由之间传递用户信息 1.1.2 主动路由协议 用于维护路由器的路由表 R2#show ip route Codes: C - ...

  5. Linux 新建文件/文件夹,删除文件文件夹,查找文件 打开文件

    1.新建文件夹:mkdir xx 2.新建文件: touch 1.py 3.删除文件/文件夹: rm -r xx  rm 1.py 4.打开文件:cat 1.py 只显示前几行 :head -2 1. ...

  6. Windows系统安装MySQL

    在Windows中安装mysql不够幸运的话,会遇到相当多的坑,当然这也算是一种财富吧,让自己碰到问题去查找解决方案.有时候不是一时半会就可以解决的.有同学说过安装mysql安装两天还没有装上.不用担 ...

  7. maven构建SSM--pox.mxl

    最近在做项目,把maven构建SSM的pom.xml文件内容小结一下: 在console中输入如下内容,使用maven创建java web项目: mvn archetype:generate -Dgr ...

  8. Scrum Meeting Alpha - 5

    Scrum Meeting Alpha - 5 NewTeam 2017/10/20 地点:主楼与4号楼之间的走廊2楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了对班级作业部分的API的包 ...

  9. elastic-search单机部署以及中文分词IKAnalyzer安装

    前提条件 elasticsearch使用版本5.6.3,需要jdk版本1.8,低于该版本不能使用 下载 https://artifacts.elastic.co/downloads/elasticse ...

  10. Hive 学习笔记(启动方式,内置服务)

    一.Hive介绍 Hive是基于Hadoop的一个数据仓库,Hive能够将SQL语句转化为MapReduce任务进行运行. Hive架构图分为以下四部分. 1.用户接口 Hive有三个用户接口: 命令 ...