"POJ 2503" Babelfish (String)

Source: Internet
Author: User

Problem

Given a dictionary, ask again.

There is a blank line between the dictionary and the query.

Cin.peek () is a pointer to the current character.

#include <iostream> #include <string> #include <map>using namespace std;map<string, String>dic ; string s, T;int f;int main () {    ios::sync_with_stdio (false);    while (CIN >> s)        if (cin.peek () = = ' \ n ')//The pointer currently points to \ n            if (!f)            {                f = 1;                Dic[s] = t;//The current read in S is alien, the t just read into is the corresponding English            }            else                cout << ((t = dic[s])! = ""? T: "eh") << "\ n";        else//Description S is a dictionary of English        {            F = 0;//f=0 represents the next to be read outside the star            t = S;        }}

Tips for handling empty lines

#include <cstdio> #include <algorithm> #include <cstring>using namespace std; #define N 100005#define M 15char s[n];int c;struct mydic{    char zh[m];//outer star    char en[m];//English} dic[n];int cmp (const mydic &a, const Mydic & AMP;B) {    return strcmp (A.zh, B.zh) >= 0;} void  Solve () {    int l = 0, r = C;    while (L < R)    {        int m = r+l >> 1;        int f = strcmp (S, Dic[m].zh);        if (f = = 0)        {            printf ("%s\n", dic[m].en);            return;        }        if (F < 0)            L = m + 1;        else            r = m;    }    printf ("eh\n");} int main () {while    (gets (s))    {        if (!s[0]) break;//read to the empty line        sscanf (S, "%s%s", Dic[c].en,dic[c].zh);        C + +;    }    Sort (dic, DIC + C, CMP);    while (gets (s))        Solve ();}

  

  

"POJ 2503" Babelfish (String)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.