zoukankan      html  css  js  c++  java
  • 多校 Babelfish

    题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/A

    密码:acm

    Sample Input
    dog ogday
    cat atcay
    pig igpay
    froot ootfray
    loops oopslay
    
    atcay
    ittenkay
    oopslay

    Sample Output cat eh loops

    分析:存和用的时候时要注意滴。gets,空格,len=0结束,空间,时间。

    先空间超限再时间超限,唉~

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <stdlib.h>
     6 #include<queue>
     7 #include<math.h>
     8 using namespace std;
     9 
    10 #define N 250
    11 #define maxn 115200
    12 
    13 char str[N],s[N],ss[N];
    14 
    15 struct node
    16 {
    17     char s1[N],s2[N];///这里开太大了要空间超限的
    18 } p[maxn];
    19 
    20 int cmp(node e,node f)
    21 {
    22     return strcmp(e.s2,f.s2)<0;
    23 }
    24 int main()
    25 {
    26     int i,j=0,k;
    27 
    28     while(gets(ss))
    29     {
    30         int a=0,b=0;
    31         int len=strlen(ss);
    32         if(len==0)
    33             break;///这样就可以完美结束了34         for(i=0; ss[i]; i++)
    35             if(ss[i]==' ')
    36             {
    37                 k=i;
    38                 break;
    39             }
    40 
    41         for(i=0; i<k; i++)
    42             p[j].s1[a++]=ss[i];
    43         for(i=k+1; i<len; i++)
    44             p[j].s2[b++]=ss[i];
    45         j++;
    46     }
    47     sort(p,p+j,cmp);
    48 
    49     while(scanf("%s", s) != EOF)
    50     {
    51         int w=0;
    52         int l=0,r=j-1;
    53         ///二分了,就不会时间超限啦
    54         while(l<=r)
    55         {
    56             int mid=(r+l)/2;
    57             if(strcmp(s,p[mid].s2)==0)
    58             {
    59                 w=1;
    60                 printf("%s
    ", p[mid].s1);
    61                 break;
    62             }
    63             else if(strcmp(p[mid].s2,s)>0)
    64                 r=mid-1;
    65             else
    66                 l=mid+1;
    67         }
    68         if(w==0)
    69                 printf("eh
    ");
    70     }
    71     return 0;
    72 }
  • 相关阅读:
    汉字在屏幕上的显示
    手机上的ROM与RAM
    数据表示和计算
    存储器的层次结构
    计算机系统概述
    Python中的文件路径的分隔符
    网络爬虫的基本原理
    iOS多线程简介
    Quartz2D简介
    iOS 事件传递响应链
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5711809.html
Copyright © 2011-2022 走看看