void main() { string strWord,strKey;int i;MSVS msvsDictionary; while(cin>>strWord) { if(strWord.compare("XXXXXX")==0)break; strKey=strWord;sort(strKey.begin(),strKey.end()); if(msvsDictionary.find(strKey)==msvsDictionary.end()) { VS vsList;vsList.push_back(strWord); msvsDictionary.insert(MSVS::value_type(strKey,vsList)); } else msvsDictionary[strKey].push_back(strWord); } while(cin>>strKey) { if(strKey.compare("XXXXXX")==0)break; sort(strKey.begin(),strKey.end()); if(msvsDictionary.find(strKey)==msvsDictionary.end())cout<<"NOT A VALID WORD"<<endl; else { sort(msvsDictionary[strKey].begin(),msvsDictionary[strKey].end()); for(i=0;i<msvsDictionary[strKey].size();i++) cout<<msvsDictionary[strKey][i]<<endl; } cout<<"******"<<endl; } }
// MSVS:map(START$END, set<Gene> ) , there is only one Gene in set void block ( MSVS &mp ){ MSVS::iterator p, pNext, pTmp; int pStart, pEnd, nextStart, nextEnd ; // two old int leftEnd, midStart, midEnd, rightStart; // three new string leftKey, midKey, rightKey; stringstream ss; if( mp.size() < 2 ) return; p = mp.begin(); pNext = p; ++pNext ; while( pNext != mp.end() ) { pStart = getStart( p->first ); pEnd = getEnd( p->first ); nextStart = getStart( pNext->first ); nextEnd = getEnd( pNext->first ); //cout << "Enter loop: p is ( " << pStart << ", " << pEnd << "), pNext is ( " << nextStart << ", " << nextEnd << " )." << endl; if( nextStart > pEnd ){ //cout << "no overlap " << endl; // (3,8 ) (9, 12 ) 9 > 8 p = pNext; ++pNext; continue; } if( nextStart > pStart ){ //cout << "insert left " << endl; leftEnd = nextStart - 1; ss.str(""); ss << pStart << "$" << leftEnd; leftKey = ss.str(); //cout << "leftKey is : " << leftKey << endl; mp.insert( MSVS::value_type ( leftKey, p->second ) ); } if( nextEnd > pEnd ){ // ( 3,10) (3,7) 10 > 7 //cout << "insert right" << endl; rightStart = pEnd + 1; ss.str(""); ss << rightStart << "$" << nextEnd ; rightKey = ss.str(); //cout << "rightKey is : " << rightKey << endl; pTmp = mp.find( rightKey ); if ( pTmp != mp.end() ) pTmp->second.insert( pNext->second.begin(), pNext->second.end() ); else mp.insert( MSVS::value_type( rightKey, pNext->second ) ); if( nextStart > pStart ){ //cout << "insert middle" << endl; midStart = nextStart; midEnd = pEnd; ss.str(""); ss << midStart << "$" << midEnd ; midKey = ss.str(); //cout << "midKey is : " << midKey << endl; mp.insert( MSVS::value_type( midKey, p->second ) ); mp.erase( p ); pTmp = mp.find( midKey ); pTmp->second.insert( pNext->second.begin(), pNext->second.end() ); p = pTmp; } else if ( nextStart == pStart ) p->second.insert( pNext->second.begin(), pNext->second.end() ); mp.erase( pNext ); pNext = p; ++pNext; } // when nextEnd <= pEnd else { pNext->second.insert( p->second.begin(), p->second.end() ); // nextStart > pStart , nextEnd <= pEnd, pNext is middle if ( nextEnd < pEnd ){ // (4,6 ) (3,8) //cout << "insert right " << endl; rightStart = nextEnd + 1; ss.str(""); ss << rightStart << "$" << pEnd ; rightKey = ss.str(); //cout << "rightKey is : " << rightKey << endl; pTmp = mp.find( rightKey ); if( pTmp != mp.end() ) pTmp->second.insert( p->second.begin(),p->second.end() ); else mp.insert( MSVS::value_type ( rightKey, p->second ) ); } mp.erase ( p ) ; p = pNext; ++pNext; } } }