CCF 201509-3 Template Generation System (stl+ simulation)

Source: Internet
Author: User
Tags cmath

Problem DescriptionChengcheng recently set up a Web site where some of the pages come from different data records in the database, but the basic structure of the pages is the same. For example, for a page that displays user information, when the user is Tom, the source code for the page is

And when the user is Jerry, the source code of the Web page is

Examples of this are many of the sites that contain dynamic content. To simplify the work of generating web pages, Chengcheng felt he needed to introduce a set of template generation systems.
A template is text that contains special tags. The template used by Chengcheng contains only a special tag in the format {{VAR}}, where VAR is a variable. The token is replaced by the value of the variable VAR when the template is generated. For example, if the variable name = "Tom", then {{name}} will generate Tom. The specific rules are as follows:
• The variable name consists of uppercase and lowercase letters, numbers, and underscores (_), and the first character is not a number and is not longer than 16 characters.
• The variable name is case-sensitive, and name and name are two different variables.
• The value of the variable is a string.
• If a variable in the tag is not defined, an empty string is generated, which is equivalent to removing the tag from the template.
• Templates are not generated recursively. That is, if the value of the variable contains the contents of a shape such as {{VAR}}, no further substitutions are made. Input FormatThe first line of input contains two integers m, n, which represent the number of rows of the template and the number of variables given when the template was generated.
Next m line, each line is a string representing the template.
Next n rows, each row represents a variable and its value, separated by a space. The value is a string, enclosed in double quotation marks ("), which can contain any printable ASCII character except double quotes (ASCII range 32, 33, 35-126). output FormatThe output contains several lines that represent the results of the template generation. Sample Input11 2
<! DOCTYPE html>
<title>user {{Name}}</title>
<p>email: <a href= "mailto:{{Email}" >{{Email}}</a></p>
<p>address: {{Address}}</p>
Name "David Beckham"
Email "[Email protected]" Sample Output<! DOCTYPE html>
<title>user David beckham</title>
<p>email: <a href= "Mailto:[email protected]" >[email protected]</a></p>
<p>address: </p>
Measuring use case size and conventions0≤m≤100
The input template has a line length of 80 characters or less (no line break).
Enter the guarantee template that all substrings starting with {{{} are valid, starting with two opening curly braces and a space, then the variable name, and ending with a space and two closing curly braces.
The value string for all variables in the input is no longer than 100 characters (not including double quotes).
Ensure that the names of all variables entered are different. Analysis: With STL simulation is good, but only 90 points, do not know which is wrong, which big God see out, tell, grateful. The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "W",  STDOUT) using namespace Std;typedef long Long ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const LL LNF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 1e4 + 5;const int mod = 1e9 + 7;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};const char *hex[] = {"0000", "00 "0010", "0011", "0100", "0101", "0110", "0111", "N", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};int N , M;const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, to, 31};const int monn[] = {0, h, H, a, A, a, a, a, a, a, a, a, 31};inline int Min (int a, int b) {return a < b? A:b;} inline int Max (int a, int b) {return a > b a:b;} inline ll Min (ll A, ll b) {return a < b a:b;} inline ll Max (ll A, ll b) {return a > b a:b;} inline bool Is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;}        vector<string> Text;int Main () {while (scanf ("%d%d", &n, &m) = = 2) {GetChar ();        String line;        Text.clear ();            for (int i = 0; i < n; ++i) {getline (cin, line);        Text.push_back (line);        } int pos;            while (m--) {string S1, S2;            Getline (cin, line);            pos = Line.find ("");            S1 = line.substr (0, POS);            S2 = Line.substr (pos+2, (int) line.size ()-pos-3);               for (int i = 0; i < n; ++i) {string &s = Text[i]; pos = 0;                    while (true) {int pos1 = S.find ("{{", POS);                    int pos2 = S.find ("}}", POS1);                    if (pos1 < 0 | | Pos2 < 0) break;                    String t = S.substr (pos1+3, pos2-pos1-3);                    if (t = = S1) s.replace (pos1, pos2-pos1+3, s2, 0, S2.size ());                pos = Pos1+s2.size ();            }}} for (int i = 0; i < n; ++i) {string &s = Text[i];            pos = 0;                while (true) {int pos1 = S.find ("{{", POS);                int pos2 = S.find ("}}", POS1);                if (pos1 < 0 | | Pos2 < 0) break;                S.replace (POS1, Pos2-pos1+3, "", 0, 0);            pos = POS1;    }} for (int i = 0; i < n; ++i) cout << text[i] << Endl; } return 0;}

CCF 201509-3 Template Generation System (stl+ simulation)

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: 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.