HDU 1075 Map's common means of using string interception and considerations for string getline use

Source: Internet
Author: User

Let's start by saying the string intercept routines, using coordinates, one input.

To check if the characters in the string are in accordance with a traversal, if so, put the character in the Intercept string and let the back coordinate move forward.

If not, intercept the end coordinate class.

Then the map using the header file for <map>

Define words map< type, type > variable name

For the incoming words of the values in the map, just use the form of the array.

There's a search here, so we're going to use the Find function if I can't find it. The Find return value is end ()

And then use the string type variable to be aware that a variable of type string will automatically release its contents before the next change to it

Topic

Problem Descriptionignatius is so lucky that he met a Martian yesterday. But he didn ' t know the language, the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate, the history book into 中文版. Can you help him?

Inputthe problem have only one test case, the test case consists of the parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should is ignored, then some lines fo Llow, each line contains and strings, the first one is a word in 中文版, the second one is the corresponding word in Mart Ian ' s language. A line with a single string "End" indicates the end of the directory part, and this string should is ignored. The book part starts with a single line contains a string "START", this string should is ignored, then an article written In Martian ' s language. You should translate the article into 中文版 with the dictionary. If you find the word in the dictionary should translate it and write the new Word to your translation if you can ' t Find the word in the "dictionary" is not a translate it, and just copy the old Word to your translation. Space ('), tab (' \ t '), enter (' \ n ') and all the punctuation shouldNot being translated. A line with a single string "End" indicates the end of the book part, and that ' s also the end of the input. All the words is in the lowercase, and each word would contain at most of the characters, and each line would contain at most 3 characters. 

Outputin This problem, you have a to output the translation of the history book.

Sample inputstartfrom Fiwohello difhmars riwosfearth fnnvklike fiiwjendstartdifh, i ' m fiwo riwosf.i fiiwj fnnvk! END

Sample Outputhello, I ' m from mars.i like earth! First on the code
#include <stdio.h>
#include <map>
#include <string>
#include <iostream>
using namespace Std;
int main ()
{
String str,b,d;
Char s[60];
int i,begin,end,j;
Map<string,string> fuck;
cin>>str;
while (cin>>str&&str!= "END")
{
if (str== "END") break;
cin>>b;
FUCK[B]=STR;
}
cin>>str; GetChar ()///////Here be especially careful to use Getline and scanf (%c) somewhat like the value entered beforehand to GetChar j=0;
while (Getline (CIN,STR) &&str!= "END")
{
if (str== "END") break;
cout<<str<<endl;
For (I=0;i<str.length (); i++)
{
if (str[i]>= ' a ' &&str[i]<= ' Z ')
{
s[j++]=str[i];//because of the automatic release of string, it is better to use s to define an array
cout<<s[j-1]<<endl;
}
Else
{
s[j]= ' + ';
cout<<s<<endl;
j=0;
D=s;
if (Fuck.find (d)!=fuck.end ())
{
cout<<fuck[d];
}
else cout<<d;
cout<<str[i];
}
}
cout<<endl;
}
return 0;
}

HDU 1075 Map's common means of using string interception and considerations for string getline use

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.