1004 - = source[i]; calc(i+1,j); epos --; pos --; p...

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

View Full Document Right Arrow Icon
#include<iostream> #include<cstring> #include<map> #include<set> #include<cstdio> # using namespace std; map<char, int> table; m int smap[1024]; char source[1024]; char dest[1024]; int slen; int dlen; i char stackop[2048]; int pos; i char stackele[2048]; int epos; i void calc(int i, int j){ int t; if(j == dlen){ i for(t =0 ; t < pos; t++){ cout<<stackop[t]<<" "; } cout<<endl; return; } if(i > slen){ return; } if(source[i] == dest[j]){ d stackop[pos ++] = 'i'; stackele[epos ++ ] = source[i]; s calc(i+1,j); epos --; pos --; p /*¡¡ÒÔÇ°ÓС¡*/ stackop[pos++] = 'o'; epos --; calc(i,j+1); stackele[epos ++] = dest[j]; pos --; } return; } /* Stackop[pos] != */ / /*¡¡ÒÔºóÓУ¿ */ / stackop[pos++] = 'i'; stackele[epos++]
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: = source[i]; calc(i+1,j); epos --; pos --; p /*¡¡ÒÔÇ°ÓС¡*/ if(epos && stackele[epos-1] == dest[j] ){ stackop[pos++] = 'o'; epos --; calc(i,j+1); stackele[epos ++] = dest[j]; pos --; } } void fun(){ int i; char alpha; map<char,int>::iterator iter; for(i=slen-1; i>= 0 ; i--){ alpha = source[i]; iter = table.find( alpha ); if(iter != table.end()){ smap[i] = table[alpha]; } else { smap[i] = 0; } table[alpha] = i; } calc(0,0); c } int main(){ while(cin>> source >> dest){ slen = strlen(source); dlen = strlen(dest); table.clear(); epos = pos = 0; cout<<"["<<endl; if(slen == dlen) fun(); cout<<"]"<<endl; } 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 / 2

1004 - = source[i]; calc(i+1,j); epos --; pos --; p...

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