Babelfish POJ
来源:互联网 发布:苹果8没网络 编辑:程序博客网 时间:2024/06/08 07:42
题意很简单,先给出一组相互映射的字符串组,左边的str1和右边的str2对应
接下来输入一行回车
接下来每输入字符串,判断之前是否输入过str2,如果没有则输出eh,否则输出str1
用了哈希表
直接给出代码
#include<iostream>#include<cstdio>#include<cstring>#include<stdlib.h>#define prime 1999using namespace std;char answer[15];typedef class HashTable{public: char str1[15]; char str2[15]; HashTable *next; HashTable() { next=0; }} HashTable;HashTable *Hash[prime];void Insert(int key,char str1[],char str2[]){ if(!Hash[key]) { HashTable *temp=new HashTable; strcpy(temp->str1,str1); strcpy(temp->str2,str2); Hash[key]=temp; } else { HashTable *p=Hash[key]; while(p->next) { p=p->next; } HashTable *temp=new HashTable; strcpy(temp->str1,str1); strcpy(temp->str2,str2); p->next=temp; }}bool Find(int key,char str[]){ if(!Hash[key]) { return false; } HashTable *p=Hash[key]; while(p) { if(!strcmp(p->str2,str)) { strcpy(answer,p->str1); return true; } p=p->next; } return false;}int main(){ int key; char t; char str1[15]; char str2[15]; memset(Hash,0,sizeof(Hash)); while(1) { t=getchar(); if(t=='\n') break; str1[0]=t; int i=1; while(1) { t=getchar(); if(t==' ') { str1[i]='\0'; break; } str1[i++]=t; } int j=1; i=0; key=0; while(1) { t=getchar(); if(t=='\n') { str2[i]='\0'; Insert(key,str1,str2); break; } key+=(t-96)*(j++); str2[i++]=t; } } char str[15]; while(cin>>str) { key=0; int l=strlen(str); for(int i=0; i<l; ++i) { key+=(str[i]-96)*(i+1); } if(!Find(key,str)) { cout<<"eh"<<endl; } else { cout<<answer<<endl; } }}
阅读全文
0 0
- poj Babelfish
- Babelfish POJ
- poj 2503 Babelfish
- POJ 2503 Babelfish(HASH)
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish 【hash】
- poj 2503 Babelfish【trie】
- POJ 2503 Babelfish
- poj-2503 Babelfish
- poj-2503 Babelfish
- poj 2503 Babelfish
- poj 2503 Babelfish
- poj 2503.Babelfish
- POJ 2503 Babelfish
- TCP三次握手与四次挥手
- Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
- LCS求最长公共子串
- Linux权限
- web安全色
- Babelfish POJ
- 单变量线性回归中的梯度下降法求解代价函数的最小值
- Linux下安装Mongodb
- LeetCode
- org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
- Oracle 12c 使用普通用户的步骤
- PAT甲级 1037 -- 没有注释
- 【CDOJ1059】秋实大哥与小朋友
- MYSQL当权限更改生效时