poj 1035KINA Is Not Abbreviation
题目链接: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的更多相关文章
- OpenJudge/Poj 2001 Shortest Prefixes
1.链接地址: http://bailian.openjudge.cn/practice/2001 http://poj.org/problem?id=2001 2.题目: Shortest Pref ...
- poj 2001 Shortest Prefixes(特里)
主题链接:http://poj.org/problem?id=2001 Description A prefix of a string is a substring starting at the ...
- POJ 2001 Shortest Prefixes (Trie)
题目链接:POJ 2001 Description A prefix of a string is a substring starting at the beginning of the given ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- 初入servlet:Allocate exception for servlet
老板,来一碗错误垫垫肚子! 如果以下几个错误都符合,估计就是这个原因了. 页面报错如下: java.lang.NoClassDefFoundError:IllegalName: firstDemo/T ...
- sql脚本
Windows下执行命令 \. d:\book.sql 这里使用了case when 这个小技巧来实现批量更新.//一个字段 UPDATE categories SET display_or ...
- Problem D: 来开个书店吧
某出版社可出版图书和磁带.其中图书按照每页的价格乘以页数进行定价,磁带根据每10分钟的价格乘以磁带录音的分钟数进行定价.请定义Publicatioin.Book.Tape以及BookStore四个类. ...
- 深入分析Android动画(一)
动画的分类: ①View动画 View动画顾名思义其作用对象为View,包含平移.缩放.旋转.透明,这四类变化分别对应着Animation的子类TranlateAnimation.ScaleAnima ...
- php缓存模块apc可能导致php-fpm终止
如果你的网站出现502错误.同时你网站中又使用了apc模块来做缓存处理.那么这篇文章兴许能帮到你. 首先,查看了php-fpm 的进程数. 发现php-fpm的进程数已经到达了php-fpm.conf ...
- SQL Server 2008 R2 企业版 MSDN原版
经网友建议,提供常用试验用资源.以下软件或系统仅为完成本博客内的各种实验而提供下载. 所有软件.系统均为该软件发布方提供的原版文件,未经任何修改.破解等操作.使用目的仅限于学习.测试及实验,符合国家相 ...
- PHP--最常用--必背函数总结!php学习者收藏必备!
一.PHP系统函数 函数 功能 用法 var_dump() 打印变量结构信息,包括类型和值.数组将递归展开值 var_dump ( $arg1...); echo():是语法结构 输出一个或者多个字符 ...
- Java 核心内容相关面试题【3】
目录 面向对象编程(OOP) 常见的Java问题 Java线程 Java集合类 垃圾收集器 异常处理 Java小应用程序(Applet) Swing JDBC 远程方法调用(RMI) Servlet ...
- Maven的pom.xml文件详解------Build Settings
根据POM 4.0.0 XSD,build元素概念性的划分为两个部分:BaseBuild(包含poject build和profile build的公共部分,见下)和poject buil < ...
- ARM开发板链接shell
1.用网线插入开发板(最好链接路由器) 2.启动开发板(可以用U盘启动) 执行 #run bootusb 3.联网 #ifconfig eth0 up #udhcpc或者#dhclient wan # ...