1052 - while(!q.empty()){ from = q.front(); q.pop();...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<map> #include<set> #include<vector> #include<queue> using namespace std; map<char , int > table[50]; set<char> leave[50]; vector<int> down[50]; int tnum; char buffer[40]; int mask[50]; void add(int n, int v){ if(buffer[0] =='.') return; int i; for(i=0; buffer[i];i++){ table[n][buffer[i]] = v; } if(v < 0) return; for(i=0;buffer[i];i++) leave[n].insert(buffer[i]); } void output(int i){ cout<<":"; set<char>::iterator iter; for(iter=leave[i].begin(); iter!= leave[i].end(); iter++){ cout<<*iter; } cout<<":"<<endl; } void fun(){ int from,to,i; queue<int> q; memset(mask,0,sizeof(mask)); cin>>from>>to; from --, to --; down[from].push_back(to); q.push(from); mask[from] = 1; cin>>from>>to; } set<char>::iterator f,st; map<char,int>::iterator t;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while(!q.empty()){ from = q.front(); q.pop(); mask[from] = 0; for(i=0;i&lt;down[from].size(); i++){ to = down[from][i]; for(f=leave[from].begin(); f!= leave[from].end(); f++){ t = table[to].find(*f); if(t-&gt;second&lt;0) continue; st = leave[to].find(*f); if(st==leave[to].end()){ leave[to].insert(*f); if(mask[to] ==0){ q.push(to); mask[to] = 1; } } } } } for(to =0; to &lt; tnum; to++){ output(to); } } int main(){ int tstcase; int i; cin&gt;&gt;tstcase; //tstcase = 1; while(tstcase --){ cin&gt;&gt;tnum; for(i=0;i&lt;tnum;i++){ table[i].clear(); leave[i].clear(); down[i].clear(); cin&gt;&gt;buffer; add(i,1); cin&gt;&gt;buffer; add(i,-1); } fun(); if(tstcase) cout&lt;&lt;endl; } return 0; }...
View Full Document

Page1 / 2

1052 - while(!q.empty()){ from = q.front(); q.pop();...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online