Example #1
0
int main(int argc, char **argv)
{
  std::setlocale(LC_ALL, "ru_RU.UTF-8");

  auto vocabulary = loadVocabulary(argv[1]);
  token_t root = std::make_tuple( 0, std::wstring(L"*root*"),
                                 -1, std::wstring(L"rroot"));
  auto sentence = sentence_t(1, root);
  std::wstring line;

  while (std::getline(std::wcin, line)) {
    line.erase(std::remove(line.begin(), line.end(), L'\n'), line.end());
    std::transform(line.begin(), line.end(), line.begin(), std::towlower);
    
    std::wistringstream stream(line);
    std::vector<std::wstring> rawSentence;

    std::copy(std::istream_iterator<std::wstring, wchar_t>(stream),
              std::istream_iterator<std::wstring, wchar_t>(),
              std::back_inserter(rawSentence));

    if (rawSentence.empty()) {
      if (sentence.size() > 1) {
        printPairs(vocabulary, sentence);
      }

      sentence = sentence_t(1, root);
    }
    else {
      int index = std::stoi(rawSentence[0]);
      auto tokenWord = rawSentence[1];
      int parentIndex = std::stoi(rawSentence[rawSentence.size() - 2]);
      auto relation = rawSentence[rawSentence.size() - 1];

      sentence.push_back(std::make_tuple(index, tokenWord,
                                         parentIndex, relation));
    }
  }

  if (sentence.size() > 1) {
    printPairs(vocabulary, sentence);
  }

  return 0;
}
Example #2
0
/* Driver program to test above function */
int main()
{
    int A[] = {-1, 4, 45, 6, 10, 8};
    int n = 16;
    int arr_size = 6;
 
    printPairs(A, arr_size, n);
 
    getchar();
    return 0;
}
Example #3
0
int main(int argc, char *argv[]) {

	if (argc != 2)
	{
		std::cout <<"Usage: ./closestPair [brute|basic|optimal]" << std::endl;
		return -1;
	}

	std::string option = argv[1];

	if (option != "brute" && option != "basic" && option != "optimal")
	{
		std::cout <<"Usage: ./closestPair [brute|basic|optimal]" << std::endl;
		return -1;
	}
	
	else if (option == "brute")
	{

		std::vector<Point> result = getPoints();
		if (result.size() < 2)
		{
			std::cout << "Not enough points to compute closest pair. Program closing." << std::endl;
			return -1;
		}

		else
		{
	    //bruteForce(result);
	    printPairs(bruteForcePairs(result));
	    return 0;
	  //   std::sort(result.begin(), result.end(), compareY());
			// for (int i = 0; i < result.size(); i++)
			// {
			// 	result[i].toString();
			// 	std::cout << std::endl;
			// }
			// return 0;
		}

	}

		else if (option == "basic")
		{
			std::vector<Point> result = getPoints();
			if (result.size() < 2)
			{
				std::cout << "Not enough points to compute closest pair. Program closing." << std::endl;
				return -1;
			}

			else
			{
				//std::cout << "entering basic sort alg" << std::endl;
		    basicSort(result);
		    return 0;
			}

		}
		else if (option == "optimal")
		{
			std::vector<Point> result = getPoints();
			if (result.size() < 2)
			{
				std::cout << "Not enough points to compute closest pair. Program closing." << std::endl;
				return -1;
			}

			else
			{
				//std::cout << "entering basic sort alg" << std::endl;
		    optimalSort(result);
		    return 0;
			}
		}
	}