POJ2503 Babelfish

POJ2503-Babelfish:编程题目解析与AC代码实现 本文还有配套的精品资源,点击获取 简介:POJ2503-Babelfish是一个在线判题系统POJ中的编程挑战,要求通过算法解决特定问题,并提交C++代码进行系统评测。包含解题报告和AC代码的压缩包,详细解释了问题理解、算法设计思路、以及时间与空间复杂度分析。该题可能与语言翻译或信息转换有关,提供了一个关于字符串处理或编码转换的实际问题解决案例。通过分析解题报告和AC代码,... 阅读详情

题目大意:给出英语 --- A国语言 ,然后输入A国语言单词,问在字典内是否有该单词,有就输出该单词英文,无则输出eh;

思路:典型的先保存再查找,有好几种解法,我用得是hash,但是再用链表的时候无限WA啊,也不知道是那个字符串哈希有问题还是链表出了问题,求强力数据找BUG啊

 


AC program:(数组哈希)

 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
char aa[15],bb[15];
char cc[15];
char w[24];
int num;
int head[100005];
struct node
{
  char str1[15],str2[15];
  int tto;
         
}next[100005];
int get_key(char tmp[])
{
    unsigned int key=0;
    unsigned int a=61891;  //unsigned保证数据不爆
    while(*tmp)
    {
      key=key*a+(*tmp++);           
    }
    return key%99991;
}
void hash_insert(char aaa[],char bbb[])
{
  int key=get_key(bbb);
  next[num].tto=head[key];
  strcpy(next[num].str1,aaa);
  strcpy(next[num].str2,bbb);///
  head[key]=num++;
    
}
void hash_find(char ccc[])
{
  int key=get_key(ccc);
  for(int i=head[key];i;i=next[i].tto)
  {
    if(strcmp(next[i].str2,ccc)==0)
      {
        printf("%s\n",next[i].str1);
        return;
      }      
  }
  printf("eh\n");     
}
int main()
{
num=1;///
memset(head,0,sizeof(head));
memset(next,0,sizeof(next));
while(gets(w) && w[0])
{
  sscanf(w ,"%s%s",aa,bb);
  hash_insert(aa,bb);              
}
while(scanf("%s",cc)!=EOF)
{ 
  hash_find(cc);                          
}
//system("pause");
return 0;}


 

 


WA program:(链表哈希,呜呜,各种WA,求数据啊)

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define HashTableSize 99991 
char aa[20],bb[20];
char cc[20];
char w[40];
typedef class HashTable
{
  public :
          char str1[20],str2[20];
          HashTable *next;
          HashTable()
          {
               next=0;
               memset(str1,0,sizeof(str1));
               memset(str2,0,sizeof(str2));///  
          }
         
}Hashtable;
 
Hashtable * hash[100005];
/*unsigned int ELFHash (const char *str)
{
  unsigned int key=0;
  unsigned int x=0;
  while(*str)
  {
    key=(key<<4)+(*str++);
    if((x=key&0xF0000000L)!=0)
     {
       key^=(x>>24);
       key&=~x;                         
     }           
  } 
  return key;//key&0x7fffffff;        
}*/
int ELFHash(char * key)
{
    unsigned int h = 0;
    while (*key){
        h = (h << 4) + *key++;
        unsigned int g = h & 0xf0000000L;
        if (g) h ^= g >> 24;
        h &= ~g;
    }
    return h;//h % 99991;
} 
void hash_insert(char aaa[],char bbb[])
{
    int key=ELFHash(bbb)%HashTableSize;
    if(!hash[key])
      {
       Hashtable *temp =new   Hashtable ; 
       //temp->str1=aaa; 
       strcpy(temp->str1,aaa);
       strcpy(temp->str2,bbb);
       hash[key]=temp;           
      }
    else
       {
                Hashtable *temp=hash[key];
                while(temp->next)
                   temp=temp->next;
                temp->next=new  HashTable;
                strcpy(temp->str1,aaa);
                strcpy(temp->str2,bbb);                          
       } 
       
} 
bool hash_find(char ccc[])
{
 int key=ELFHash(ccc)%HashTableSize;
 if(!hash[key])
    return false;
 else
     {
              Hashtable *temp=hash[key];
              while(temp)
              {
                if(strcmp(temp->str2,ccc)==0)
                {
                  printf("%s\n",temp->str1);
                  return true;                             
                } 
                temp=temp->next;          
              }
                    
     }
     return false;     
} 
int main()
{
memset(hash,0,sizeof(hash));  
/*while(1)
      {
           
            if((aa[0]=getchar())=='\n')break;
            scanf("%s%s",aa+1,bb);
            insert(aa,bb);
            //getchar();
      }*/
 
while(gets(w) && w[0]!=0)
  {
    sscanf(w,"%s %s",aa,bb);
    hash_insert(aa,bb);//add(a,b);
  } 
while(scanf("%s",cc)!=EOF)/// 
{
   if(!hash_find(cc))
     printf("eh\n");                         
} 

                                   
return 0;} 


 

 

C语言Poj答案全完整打包 C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友 立即下载

相关推荐

POJ2503-Babelfish

北大POJ2503-Babelfish 解题报告+AC代码

POJ 2503 Babelfish (神族文字)

BabelfishTime Limit: 3000MSMemory Limit: 65536KTotal Submissions: 47332Accepted: 19828DescriptionYou have just moved from Wa...

weixin_34185320的博客 229

电子工程师必看:2024年IPC-A-610J和J-STD-001J新标准到底更新了啥?

本文深入解析2024年IPC-A-610J和J-STD-001J新标准的核心更新,重点关注电子制造领域的验收标准与工艺参数变化。新版标准强化了高密度组装和微焊接工艺的规范,包括焊料润湿角调整、BGA空洞率严格化等关键变更,为电子工程师提供实用指南。同时关联IPC-7711/21D和IPC-2221C的配套更新,助力企业快速适应新标准要求。

weixin_33694620的博客 782

poj-2503 Babelfish

Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

心の コード 406

如何从RHEL 8升级到RHEL 9

Red Hat 于 2022 年 5 月 17 日宣布全面推出 RHEL 9。这是 RHEL(Red Hat Enterprise Linux)的最新版本,它具有许多功能和增强功能。

u012748257的博客 1019

【Python计量】linearmodels面板数据回归(一)

我们以伍德里奇《计量经济学导论现代方法》的”第14章高级面板数据方法“的案例14.1为例,使用jtrain中的数据来进行固定效应估计。

mfsdmlove的博客 9277

poj 2503

题目大意:给你一个字典,先输入一个字典,每行两个单词,但一个是英文,第二个是外文,字典输入以空行结束,然后再输入外文单词,如果字典有这个单词就输入英文的单词,否则输出eh。 注意:首先字典要以空行结束,那么只能用可以识别空行的char类型来做,可以用getline()函数,然后是如何快速再找问题,如果直接查找无疑会超时,可以用二分查找 这里用到besearch()函数; C语言中 bsear

博客模版 602

OpenClaw 股票自动化交易实践指南:从原理到实战的完整技术路径

量化交易策略的开发是一个系统工程,需要综合运用金融知识、编程技能和数据分析能力。OpenClaw通过引入提示词工程技术,大大降低了策略开发的技术门槛,使得更多投资者能够参与到量化交易中来。但技术只是工具,真正决定策略成败的是对市场的深刻理解和严格的风险管理。本章系统介绍了OpenClaw环境下的策略开发方法,从提示词驱动到传统代码实现,从参数优化到回测验证,涵盖了策略开发的完整流程。提示词驱动方式适合快速验证交易想法,传统代码方式适合实现复杂的定制逻辑,两种方式可以协同使用,发挥各自的优势。

lovely_yoshino的博客 5990

POJ-2503 Babelfish

POJ-2503 Babelfish(排序加二分查找 ) POJ-2503 题目大意:给定一些字符串和其对应的字符串 在给定一些需要查找的字符串 输出查找字符串的对应字符串 若查找字符串并不存在 则输出eh 解题思路:首先这个题给出的字符串<100000 直接对遍历查找肯定会超时 所以就会想到二分查找 二分查找前提字符串顺序排列 如果单纯的对字符串排序 那么字符串和对应字符串之间的关系就会打...

鱼头的水题之路 640

华为OD机试新系统真题-谁没交卷(Java /Py/C++/Go/C/Js)

华为OD机试 新系统真题【谁没交卷】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【谁没交卷】多语言题解。

qq_45776114的博客 421

物联网Node-Red开发教程-第6章 HTTP与Web服务

本章摘要(147字): 本章系统讲解了Node-RED中的HTTP节点应用,重点包括: 三大核心HTTP节点功能:http in(接收请求)、http response(返回响应)、http request(调用外部API) 详细演示了REST API开发流程,包括路径参数(req.params)处理和响应构造 提供了创建Hello World API、传感器数据接口等实用示例 涵盖HTTP方法特性、状态码设置及响应头配置等关键知识点 通过流程图和JSON配置直观展示节点连接方式,帮助快速掌握Web服务开发

shihui2003的博客 264

C++POJ2503BabelFish

C++POJ2503BabelFish 问题描述: 你刚从滑铁卢搬到大城市。这里的人们讲一种难以理解的外语方言。幸运的是,你有一本字典来帮助你理解它们。 输入: 输入包括多达 100,000 个字典条目,然后是空白行,然后是多达 100,000 个单词的消息。每个字典条目都是一行包含一个英语单词,然后是一个空间和一个外语单词。字典中每个外来词只出现一次。信息是外语中的一系列单词,每行一个单词。输入中的每个单词最多是 10 个小写字母的序列。 输出: 输出是翻译成英文的消息,每行一个单词。字典中未写的外来词应

Laborious_Bee的博客 876

【Codecs系列】HEVC-SCC(一):核心技术介绍

DATE: 2020.6.4【Tags: HEVC SCC】 1、参考网址 2、SCC简介 3、HEVC-SCC核心技术

优快云明星博主,认证博客专家,视频、Matlab领域优质创作者。 4804

POJ 2503 Babelfish // 字符串映射,Trie

题目描述POJ 2503 Babelfish解题思路题目大意: 给一些单词A及其对应的单词B,比如 dog -> ogday, 然后再输入单词B,输出单词A,若输入的B不存在映射,则输出”eh“.用STL的map应该可以水过去,但是还是用Trie实现一下~~参考代码//********************************************** // Author: @xmzyt

FZU_zyt的专栏_(:з」∠)_ 442

CAPL编程规范与最佳实践

通过本文的学习,读者应该对CAPL编程规范与最佳实践有了初步的了解,并能够编写高质量的CAPL脚本。在实际项目中,CAPL的应用非常广泛,希望读者能够通过不断的学习和实践,掌握更多的CAPL技巧,提高自己的开发能力。

闲人编程的博客 1748

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ-2503 Babelfish(字典树)

POJ-2503 Babelfish(字典树) 题解:只需将两个单词分别存于string[]数组和字典树中即可。 每个单词的end数组存储对应单词的所位于的数组下标,通过search函数返回数组下表找到对应单词即可。 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; class node{ public: n

m0_53846741的博客 890

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 刷题系列:2503. Babelfish

POJ 刷题系列:2503. Babelfish 传送门:2503. Babelfish 题意: 翻译:给出一英文单词和与之对应的外文,组成字典集。后续当给出一个外文单词时,求出对应的英文单词。 思路: 无脑 HashMap,外文为key,英文单词为value,存入hashMap。 代码如下: import java.io.IOException; import java

Demon-初来驾到 464

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

POJ - 2503 Babelfish(map)

POJ - 2503 Babelfish 直接用cin,cout时间超限,用一个加速器,就可以水过去。 #include<iostream> #include<map> using namespace std; int main() { ios::sync_with_stdio(false);//c++加速器 string s,a,b; map<string,string>x; while(getline(cin,s)) { int l=s.siz

00后的博客 194

POJ 2503 Babelfish(map)

题目传送门 题目中文翻译: Description 你刚从滑铁卢搬到了一个大城市。这里的人们说的是一种难以理解的外语方言。幸运的是,你有一本词典来帮助你理解它们。 Input 输入由最多100,000个字典条目组成,后面跟着一个空行,再后面跟着最多100,000个单词的消息。每个字典条目都是一个包含英文单词的行,后跟一个空格和一个外语单词。字典中同一个外语单词不会出现多次。消息...

anshuo0835的博客 898

poj 2503 Babelfish(字典树)

poj 2503 Babelfish 和map一个意思,写下字典树练手,输入太恶心了

yjCola 600

POJ_2503 Babelfish 字典树

题目链接:http://poj.org/problem?id=2503 依旧字典树 注意新建节点初始化值,读取数据的时候可以用gets判空行,最后删除分配的空间防RE 评论区还有用map过的,比较耗时。 代码: 1 #include <cstdio> 2 #include <cstdlib> 3 #include <iostream&...

weixin_30426957的博客 109

ACM POJ 2503 (Babelfish)

题目链接 http://poj.org/problem?id=2503 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); Trie trie = new Trie(); while

陈青杨 958

poj2503 Babelfish

A - Babelfish Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2503 Description You have just moved from Waterloo to a big ci

樱花满地集于我心,楪舞纷飞祈愿相随 391

poj-2503-Babelfish-字典树orMAP or 字符串哈希

题意:   给你一组字符串, 每一行有两个串,a,b;   输入空行结束   给你一个串c,问你在前面的第二列的数组中出没出现过,有的话,输出前面的那个,没有的话输出eh   sscanf函数应用是,把一个串,分割成不同类型的 1. map  2625ms #include #include #include #include #include #include #include

命运在指间 807
上一篇: The 37th ACM/ICPC Asia Regional Tianjin Site Online Contest - A.B.J
下一篇: 求1000以内的阶乘 组合数学基础练习例子(二)
muximuxi525
博客等级 码龄15年 134粉丝 294原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值