1044 - return false;...

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

View Full Document Right Arrow Icon
#include<iostream> #include<cstring> #include<string> #include<map> #include<set> using namespace std; enum { SIZ = 104, }; struct cmp{ return strcasecmp(a.c_str(), b.c_str()) < 0; } }; char buf[SIZ]; map<string, map<string, set<int>, cmp>, cmp> tab; const char *strBlank = " \t\n\r"; char *trim(char *s){ int len = strlen(s); s[--len] = 0; } while(isblank(*s)) ++s; return s; } void work(char *s, int pageNo){ char *p = index(s,'%'); if (p) s = p + 1; p = index(s, '$'); if (p){ *p++ = 0; } s = trim(s); if (p){ p = trim(p); }else{ p = ""; } string a(s); string b(p); tab[a][b].insert(pageNo); } void parse(const char *str){ tab.clear(); int pageNo = 1; while(*str){ ++pageNo; } if(*str=='{'){ ++str; int i=0;
Background image of page 1

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

View Full DocumentRight Arrow Icon
while(*str!='}'){ buf[i++] = *str; ++str; } buf[i] = 0; work(buf, pageNo); } ++str; } } bool fun(){ string s; gets(buf); if (strcmp(buf,"**")==0)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return false; while(strcmp(buf,&quot;*&quot;)!=0){ s += buf; gets(buf); } parse(s.c_str()); return true; } void outSet(set&lt;int&gt; &amp;s){ for(set&lt;int&gt;::iterator it=s.begin(); it!=s.end(); ++it){ printf(&quot;, %d&quot;, *it); } } void outstr(const string&amp;s, map&lt;string, set&lt;int&gt;, cmp&gt; &amp;item){ map&lt;string, set&lt;int&gt;, cmp&gt;::iterator it; printf (&quot;%s&quot;, s.c_str()); bool f = true; for (it=item.begin(); it!=item.end(); ++it){ if (it-&gt;first==&quot;&quot;){ outSet(it-&gt;second); continue; } printf(&quot;\n+ %s&quot;, it-&gt;first.c_str()); outSet(it-&gt;second); f = false; } printf(&quot;\n&quot;); } void output(){ map&lt;string, map&lt;string, set&lt;int&gt;, cmp&gt;, cmp&gt;::iterator it; for (it=tab.begin(); it!=tab.end(); ++it){ outstr(it-&gt;first, it-&gt;second); } } int main(){ int doc = 0; for(;fun();){ printf(&quot;DOCUMENT %d\n&quot;, ++doc); output(); } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Page1 / 3

1044 - return false;...

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

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