NYOJ542 Trial Products,< > Abuse Heart simulation problem

Source: Internet
Author: User

Time limit of trial products: +Ms | Memory Limit:65535KB Difficulty:4
Describe

The Dr.kong of ZZ University recently found that many prototypes of laboratories have been exhausted. Due to the limited funding of the project, Dr.kong decided to use the existing prototype in the laboratory to produce the missing samples. To this end, Dr.kong a few days a day to finish out a research material and let graduate bill to experiment and statistics can produce how many kinds of missing test products.

Bill went through all the information, found that the material is filled with a lot of chemical equations, in addition to uppercase and lowercase letters, numbers, plus, equal sign, there is no other symbol. wherein, each equation is a1+a2+......+Ap=b1+b2+......+Bq form, indicating a prototype product A1, A2,...... and Ap reaction, generated a prototype product B1,b2,......,Bq. Where ai and BJ are a chemical formula of a single substance or compound (not exceeding 10 characters in length), 1≤p,q≤20. The total length of each equation is no more than 100 characters. The chemical formula of some products may not be found in the periodic table of chemical elements in modern society, as a result of possible physical reactions during chemical reactions.

Bill has a headache, which experiment to start with? Can you help him?

Input
There are multiple sets of test data.
First line: N indicates the number of chemical equations written by Dr.kong (1<=n<=400)
Next there are n rows, each line being an equation.
The next line: M indicates how many kinds of products have been tried. (1<=m<=500)
Next there are m lines, each of which is the chemical formula of a test product already in place.
Output
The
first line contains a number T, which indicates how many of the missing samples can be produced.
In the next T-line, the chemical formula for the resulting sample is output in ascending ASCII code.
Sample input
4h2o+na=naoh+h2cl2+h2=hclfe+o2=fe3o4naoh+hcl=h2o+nacl3h2onacl2
Sample output
4h2hclnaclnaoh
Source
fifth session of Henan Province Program design Competition
Uploaded by

Acm_ Li Rubing



Ideas:

Because the data is very small then the infinite traversal of the equation, the existing material into the map, decomposition of the equation, so as to determine whether the equation occurs, the occurrence of the generated matter into the map, when there is no new equation occurs, it will not happen again


#include <bits/stdc++.h>using namespace std;struct fcs{string sz;    bool fs;//equation, there is a fs mark occurrence no}a[444];int main () {int n,m,i,j;            while (scanf ("%d", &n) ==1) {for (i=0;i<n;++i) {cin>>a[i].sz;        A[i].fs=false;        } scanf ("%d", &m);            Map<string,bool> jb;//uses a map to indicate that the right point bool of an existing material is a generated or reactant for (i=0;i<m;++i) {string S;            cin>>s;        Jb[s]=false;            } bool sad=true;//Tag variable When judging if there is an equation occurring while (sad) {sad=false;                for (I=0;i<n;++i) {if (A[I].FS)//The equation has occurred without looking at continue;                int len,gfs=0; String wz;//decomposition equation to derive a single substance for (J=0,len=a[i].sz.size (); j<len;++j) {if (A[i] . sz[j]== ' + ' | |                            a[i].sz[j]== ' = ')//+ or equal to the end {if (!jb.count (WZ))//indicates that the substance does not exist for direct exit    Break                    Wz= "";                            The IF (a[i].sz[j]== ' = ')//equals sign indicates that all matter has this equation can occur {a[i].fs=true;//mark this equation for the occurrence of                        sad=true;//the wheel has material generated gfs=1;//mark break;                    } continue;                } wz+=a[i].sz[j];//Connection//if (a[i].sz[j]!= ' + ' &&a[i].sz[j]!= ' = ')                    } if (GFS)//Add the resulting object to {wz= "";                            for (++J;J&LT;LEN;++J)//{if (a[i].sz[j]== ' + ') {                                if (Jb.count (WZ))//Generate material to be sentenced to weight {wz= "";                            Continue                            } Jb[wz]=true;//insert wz= ""; ContInue;                    } Wz+=a[i].sz[j];                } if (!jb.count (WZ))//The last one also to be sentenced to heavy, the first time to pay WA jb[wz]=true;        }}} cout<< (Jb.size ()-m) <<endl;        Map<string,bool>::iterator P=jb.begin ();            while (P!=jb.end ())//output {if (P->second) cout<<p->first<<endl;        p++; }} return 0;}

Freshman time this inscribed for two days, the heart is broken, after a year to re-come again, feel good


NYOJ542 Trial Products,< > Abuse Heart simulation problem

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.