Ejemplo n.º 1
0
void search() {
    if(!vis[v[0]][v[1]][v[2]][v[3]]) {
        vis[v[0]][v[1]][v[2]][v[3]] = true;
        maxans = max(maxans, ans);
        if(s.size() == 5)
            return;
        for(int i = 0; i < 4; ++i) {
            if(v[i] < n) {
                if(!s.find(bd[v[i]][i])) {
                    s.insert(bd[v[i]][i]);
                }
                else {
                    s.erase(bd[v[i]][i]);
                    ++ans;
                }
                ++v[i];
                search();
                --v[i];
                if(!s.find(bd[v[i]][i])) {
                    s.insert(bd[v[i]][i]);
                    --ans;
                }
                else {
                    s.erase(bd[v[i]][i]);
                }
            }
        }
    }
}
Ejemplo n.º 2
0
//the case if encounter a angle bracket "["
void MDparser::angleBracket(std::string& tobeStored, bool& readyToStore, std::ifstream& myinput, myset<std::string>& allWords, myset<std::string>& allLinks){
	string buffer("");

    char letter=(char)myinput.get();
    while(letter!=']'&& !myinput.fail()){
      buffer=buffer+letter;
      letter=(char)myinput.get();
   }
   buffer+="]";
   //parsing,change bool varibale to false
   for (int i=0;i<(int)buffer.size();i++){
   		letter=buffer[i];
   		if(isLetter(letter)){
   			readyToStore=true;
   			tobeStored+=letter;
   		}
   		else if(!isLetter(letter)&&readyToStore){
   			allWords.insert(tobeStored);
   			tobeStored="";
   			readyToStore=false;
   		}
   		else if(!isLetter(letter)&&!readyToStore){
   			//donothing
   		}
   }

   if(!myinput.fail()){
   	   letter=(char)myinput.get(); //get the next letter after']'
		if(letter=='('){
			buffer="";
			letter=(char)myinput.get();
			while(letter!=')'){
				buffer+=letter;
				letter=(char)myinput.get();
			}
			ifstream my_input(buffer.c_str());
			if(!my_input.fail()){
				allLinks.insert(buffer);				
			}
			my_input.close();
			buffer="";
			readyToStore=false;
		}
		else{
			if(isLetter(letter)){
				readyToStore=true;
				tobeStored+=letter;
			}
			else{
				readyToStore=false;
			}
		}
   }
}
Ejemplo n.º 3
0
void MDparser::parse(std::string filename, myset<std::string>& allWords, myset<std::string>& allLinks){
	ifstream myinput(filename.c_str());
	string tobeStored("");
	char nextCharacter;
	bool readyToStore=false;
	while(true){
		nextCharacter=(char)myinput.get();
		if(myinput.fail()){
			if(readyToStore){
				allWords.insert(tobeStored);
			}
			myinput.close();
			return;
		}
		//case when the next character is open parathesis
		if(nextCharacter=='['){
			if(readyToStore){
				allWords.insert(tobeStored);
				readyToStore=false;
				tobeStored="";
			}
			angleBracket(tobeStored,readyToStore, myinput, allWords, allLinks);

		}
		else if(isLetter(nextCharacter)){
			readyToStore=true;
			tobeStored+=nextCharacter;

		}
		else if(readyToStore&&!isLetter(nextCharacter)){
			allWords.insert(tobeStored);
			readyToStore=false;
			tobeStored="";
		}

	}
}