void findResult(string &s,
                    int pos,
                    vector<string> &temp,
                    vector<vector<string>> &results) {
        if (pos == s.size()) {
            results.push_back(temp);
            return;
        }

        bool tag = true;
        // i is len;
        for (int i = 0; pos + i < s.size(); i ++) {
            tag = true;
            int l = pos;
            int r = pos + i;
            while (l <= r) {
                if (s[l] != s[r]) {
                    tag = false;
                    break;
                }
                l ++;
                r --;
            }
            if (tag) {
                temp.push_back(s.substr(pos, i+1));
                findResult(s, pos+i+1, temp, results);
                temp.pop_back();
            }
        }
        return;
    }
    /**
     * @param s: A string
     * @return: A list of lists of string
     */
    vector<vector<string>> partition(string s) {
        // write your code here
        vector<vector<string>> results;
        vector<string> temp;

        findResult(s, 0, temp, results);

        return results;
    }
예제 #3
0
executionResult matchCheckInPcre(char pattern[], char inputString[])
{
	/*
	 * This function is called from the other file, SSNCheck.c.
	 */
	executionResult result;
	pcre2_code *re;

	if (buildPcreCode(pattern, &re) == fail) return executionFailed;
	result = findResult(re, inputString);
	pcre2_code_free(re);

	return result;
}
void ResultsItemModel::addResults(const std::vector<SpectralLibraryMatch::MatchResults>& theResults,
   const std::map<Signature*, ColorType>& colorMap, Progress* pProgress, bool* pAbort)
{
   if (theResults.empty())
   {
      return;
   }

   bool findPrevious = (rowCount() > 0);  // don't look for previous results if model is empty.
   if (pProgress != NULL)
   {
      pProgress->updateProgress("Adding Match Results to Results Window...", 0, NORMAL);
   }
   unsigned int resultCount(0);
   unsigned int numResults = theResults.size();
   mResults.reserve(mResults.size() + numResults);
   for (std::vector<SpectralLibraryMatch::MatchResults>::const_iterator it = theResults.begin();
      it != theResults.end(); ++it)
   {
      if (pAbort != NULL && *pAbort)
      {
         if (pProgress != NULL)
         {
            pProgress->updateProgress("Adding Match Results to Results Window canceled by user", 0, ABORT);
         }
         return;
      }

      // Get the results item if it already exists
      ResultsItem* pItem(NULL);
      bool newItem(false);
      if (findPrevious)
      {
         pItem = findResult(it->mTargetName, it->mAlgorithmUsed);
      }

      // Add the top-level item for the results
      if (pItem == NULL)
      {
         int resultsRow = static_cast<int>(mResults.size());
         beginInsertRows(QModelIndex(), resultsRow, resultsRow);

         // Set the target name and algorithm name in the item constructor so that they will be available when
         // the sort model automatically sorts the top-level results items when endInsertRows() is called
         QString targetName = QString::fromStdString(it->mTargetName);
         QString algorithmName = QString::fromStdString(
            StringUtilities::toDisplayString<SpectralLibraryMatch::MatchAlgorithm>(it->mAlgorithmUsed));

         pItem = new ResultsItem(targetName, algorithmName);
         newItem = true;
         mItemMap[getKeyString(it->mTargetName, it->mAlgorithmUsed)] = pItem;
         mResults.push_back(pItem);

         endInsertRows();
      }

      // Get the index for the top-level results item
      int resultsRow = getRow(pItem);
      QModelIndex resultsIndex = index(resultsRow, 0);

      // If the results item already exists, remove any existing signature match rows
      if (newItem == false)
      {
         int signatureRows = pItem->rows();
         if (signatureRows <= 0)
         {
            // Set the number of rows to 1 to account for the row indicating no matches are found
            signatureRows = 1;
         }

         beginRemoveRows(resultsIndex, 0, signatureRows - 1);
         pItem->clear();
         endRemoveRows();
      }

      // Add the updated signature match rows
      int signatureRows = it->mResults.size();
      if (signatureRows <= 0)
      {
         // Set the number of rows to 1 to account for the row indicating no matches are found
         signatureRows = 1;
      }

      mAddingResults = true;
      beginInsertRows(resultsIndex, 0, signatureRows - 1);
      pItem->setData(*it, colorMap);
      endInsertRows();
      mAddingResults = false;

      // Update the progress
      if (pProgress != NULL)
      {
         ++resultCount;
         pProgress->updateProgress("Adding Match Results to Results Window...",
            resultCount * 100 / numResults, NORMAL);
      }
   }
   if (pProgress != NULL)
   {
      pProgress->updateProgress("Finished adding Match Results to Results Window.", 100, NORMAL);
   }
}
QModelIndex ResultsItemModel::getItemIndex(const std::string& name,
   const SpectralLibraryMatch::MatchAlgorithm& algoType)
{
   ResultsItem* pItem = findResult(name, algoType);
   return index(getRow(pItem), 0);
}