A - Babelfish(6.1.2)(6.1使用词典解题实验范例)
来源:互联网 发布:window7连接网络打印机 编辑:程序博客网 时间:2024/06/06 06:30
Description
Input
Output
Sample Input
dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Sample Output
catehloops
Hint
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char dict[100010][2][15];
int n;
bool isblank(char s[])
{
int k=strlen(s);
while(--k>=0)
if(s[k]>='a'&&s[k]<='z')
return false;
return true;
}
void swap(char a[],char b[])
{
char temp[15];
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
void sort(int a,int b)
{
if(a>=b)
return ;
int mid;
char t[15];
strcpy(t,dict[(a+b)/2][1]);
int i,j;
i=a-1;
j=b+1;
do
{
do
++i;
while(strcmp(t,dict[i][1])>0);
do
--j;
while(strcmp(t,dict[j][1])<0);
if(i<j)
{
swap(dict[i][1],dict[j][1]);
swap(dict[i][0],dict[j][0]);
}
}while(i<j);
sort(a,j);
sort(j+1,b);
}
int find(char t[])
{
int mid,le,ri;
le=0;ri=n;
while(le+1<ri)
{
mid=(le+ri)/2;
if(strcmp(dict[mid][1],t)<=0)
le=mid;
else
ri=mid;
}
if(strcmp(dict[le][1],t))
return -1;
return le;
}
int main()
{
char s[30];
n=0;
gets(s);
while(!isblank(s))
{
//strcpy(dict[n][0],s);
sscanf(s, "%s%s", dict[n][0], dict[n][1]);
// if((dict[n][0]))
// break;
++n;
gets(s);
}
//sort(0,n-1,dict);
int min;
sort(0,n-1);
while(scanf("%s", s)!=EOF)
{
int k=find(s);
if(k<0)
printf("%s","eh");
else
printf("%s",dict[k][0]);
printf("\n");
}
return 0;
}
- A - Babelfish(6.1.2)(6.1使用词典解题实验范例)
- A - Babelfish(6.1.2)(6.1使用词典解题实验范例)
- F - Babelfish解题报告(黄杰)
- F - Babelfish解题报告(map函数)(陈渊)
- A - Babelfish
- Babelfish(6.1.2)(sort结构体排序)(sscanf()基本使用方法)(二分法)
- POJ2503 Babelfish(hash)
- uva10282 - Babelfish(字典)
- Babelfish(map容器)
- POJ2503 Babelfish (map)
- 思想实验(逻辑思维)解题
- poj 2503 Babelfish(字典树或STL水题) 解题报告(百炼2804)
- POJ_2503 Babelfish解题报告.
- F - Babelfish解题报告
- A - Hardwood Species(7.1.1)(利用STL中自带的排序功能编程的实验范例)
- UIReferenceLibraryViewController的使用(调用系统词典)
- POJ 2503 BABELFISH (HASH)
- POJ 2503 Babelfish(Trie)
- HDU 1711 Number Sequence //简单kmp
- linux下5个查找命令find locate whereis which type
- 【leetcode】Word Break && Word Break II
- jquery 解析xml文档 读取属性及文本内容
- win8最好用的浏览器官网免费下载
- A - Babelfish(6.1.2)(6.1使用词典解题实验范例)
- SecureCRT上传下载文件
- 《Linux》天影linux系列笔记一——linux常用命令详解:more
- wifi智能营销 wifi广告路由器
- 给JSP网站添加登录时的验证码
- (书稿底稿)(C/C++)第一章:CPU基础知识 1.1CPU和程序的执行
- 转转:解决Error"基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系。"
- 【组队赛三】-C cf448B
- POJ2479——Maximum sum