比赛 |
20150424 |
评测结果 |
AWEEEEEAAE |
题目名称 |
物质起源 |
最终得分 |
30 |
用户昵称 |
KZNS |
运行时间 |
0.595 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2015-04-24 11:08:07 |
显示代码纯文本
#include<fstream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
map<string,bool>eu;
vector<string>es;
string NO0(string s){
string a;
for(int i=1;i<s.length();i++)
a+=s[i];
return a;
}
class fangchengshi{
public:
vector<string>from,become;
void get_fcs(string s){
int i;
string u="0";
for(i=0;i<s.length();i++){
if(s[i]=='+'){
from.push_back(u);
u="0";
}
else if(s[i]=='='){
from.push_back(u);
u="0";
goto getbecome;
}
else
u+=s[i];
}
getbecome:
for(i++;i<s.length();i++){
if(s[i]=='+'){
become.push_back(u);
u="0";
}
else
u+=s[i];
}
become.push_back(u);
sort(from.begin(),from.end());
sort(become.begin(),become.end());
}
}fcs[403];
bool fcsu[403]={false};
int main(){
ifstream fi("origin.in");
ofstream fo("origin.out");
int n,m;
string s;
fi>>n;
for(int i=0;i<n;i++){
fi>>s;
fcs[i].get_fcs(s);
}
fi>>m;
vector<string>ls;
for(int i=0;i<m;i++){
fi>>s;
s="0"+s;
ls.push_back(s);
eu[s]=true;
}
sort(ls.begin(),ls.end());
e2:
for(int i=0;i<n;i++){
if(!fcsu[i]){
int j=0,k=0;
while(j<fcs[i].from.size())
if(fcs[i].from[j]==ls[k]){
j++;
k++;
}
else if(ls[k]<fcs[i].from[j])
k++;
else
goto e1;
j=0;
for(;j<fcs[i].become.size();j++)
if(!eu[fcs[i].become[j]]){
ls.push_back(fcs[i].become[j]);
es.push_back(NO0(fcs[i].become[j]));
eu[fcs[i].become[j]]=true;
}
sort(ls.begin(),ls.end());
fcsu[i]=true;
goto e2;
}
e1:;
}
sort(es.begin(),es.end());
fo<<es.size()<<endl;
for(int i=0;i<es.size();i++)
fo<<es[i]<<endl;
return 0;
}