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 ...
随机推荐
- poj 1254 Hansel and Grethel
Hansel and Grethel Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2199 Accepted: 100 ...
- GCD Again
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- scrollWidth,clientWidth,offsetWiddth,innerWinth 元素定位
getBoundingClientRect()方法.它返回一个对象,其中包含了left.right.top.bottom四个属性,分别对应了该元素的左上角和右下角相对于浏览器窗口(viewport)左 ...
- HTML学习笔记 css定位浮动及瀑布流案例 第十三节 (原创) 参考使用表
#fd { width: 100px; height: 150px; background-color: forestgreen; float: left; } #sd { width: 150px; ...
- iOS字符串修改及运用
//创建字符串 直接赋值 NSString *lytTest = @"A common string"; 1.获取字符串的长度 NSLog(@"%d",lytT ...
- (二): 基于ZeroMQ的实时通讯平台
基于ZeroMQ的实时通讯平台 上篇:C++分布式实时应用框架 (Cpp Distributed Real-time Application Framework)----(一):整体介绍 通讯平台作为 ...
- thinkphp后台ajaxReturn提示下载的问题
thinkphp新版设置了ajaxreturn方法如果是JSON格式会自动设置头信息为JSON格式,这样做在谷歌下可以正常解析,但是在IE和OPERA浏览器下就会提示下载,从而导致程序出错,修改方法如 ...
- pycharm安装和首次使用
PyCharm 是由 JetBrains 打造的一款 Python IDE,支持 macOS. Windows. Linux 系统. PyCharm 功能 : 调试.语法高亮.Project管理.代码 ...
- 【游戏开发】Excel表格批量转换成CSV的小工具
一.前言 在工作的过程中,我们有时可能会面临将Excel表格转换成CSV格式文件的需求.这尤其在游戏开发中体现的最为明显,策划的数据文档大多是一些Excel表格,且不说这些表格在游戏中读取的速度,但就 ...
- Liunx文件解压与压缩
文件压缩和解压缩 常见压缩格式如下 .zip .gz .bz2 .tar.gz .tar.gz2 .zip压缩 zip 压缩文件名 源文件 压缩文件 zip -r(递归) 压缩文件名 源目录 压缩目录 ...