int main() {
    string s1, s2;
    Solution s;
    while (cin >> s1 >> s2)
        cout << s.isScramble(s1, s2) << endl;
    return 0;
}
Example #2
0
int main(int argc, char const *argv[])
{
	Solution sl;
	int res = sl.numDecodings("1201");
	cout<<"res is "<<res<<endl;
	return 0;
}
int main() {

    ListNode *e1=new ListNode(-1);
    ListNode *e2=new ListNode(5);
    ListNode *e3=new ListNode(1);
    ListNode *e4=new ListNode(4);
    ListNode *e5=new ListNode(6);
    ListNode *e6=new ListNode(4);
    ListNode *e7=new ListNode(5);
    ListNode *e8=new ListNode(6);

    ListNode *l1 = NULL;

    ListNode *l2 = e1;
    e1->next = e2;

    ListNode *l3 = e3;
    e3->next = e4;
    e4->next = e5;

    ListNode *l4 = e6;
    e6->next = e7;
    e7->next = e8;

    print(l1); 
    print(l2); 
    print(l3); 
    print(l4); 


    vector<ListNode*> ls{l1,l2,l3,l4};
    Solution s;
    ListNode *l1234 = s.mergeKLists(ls);
    print(l1234);
}
Example #4
0
int main()
{
    TreeNode *root = new TreeNode(0);
    Solution solution;
    cout << solution.isSymmetric(root) << endl;
    return 0;
}
TEST(RemoveDuplicatesFromSortedArray, test1) {
    Solution s;
    vector<int> nums = {1, 1, 2};
    EXPECT_EQ(s.removeDuplicates(nums), 2);
    EXPECT_EQ(1, nums[0]);
    EXPECT_EQ(2, nums[1]);
}
void findFullSolutions(BivariatePolynomial * Bp1, BivariatePolynomial * Bp2, ProblemSolver * PS)
{
    int numSols = PS->getNumOfSols();
    for (int i = 0; i < numSols; ++i) {								//For every solution
        Solution * sol = PS->getSolution(i);
        if(sol->getMultiplicity() > 1) {                           //if multiplicity of solution is 1 back substitute the sols and check if they nullify the polynomials
            Polynomial * result1 = Bp1->backSubstitute(sol->getY(), PS->getHiddenVar());
            Polynomial * result2 = Bp2->backSubstitute(sol->getY(), PS->getHiddenVar());
            int numRoots1, numRoots2;
            double * roots1 = result1->computeAndGetRoots(numRoots1);
            double * roots2 = result2->computeAndGetRoots(numRoots2);
            int index = 0;
//            cout<<"roots 1"<<endl;
//            for(int i = 0; i < numRoots1; i++)
//                cout<< roots1[i]<<endl;
//            cout<<"roots 2"<<endl;
//            for(int i = 0; i < numRoots2; i++)
//                cout<< roots2[i]<<endl;
            for(int i = 0; i < numRoots1; i++)
            {
                for(int j = 0; j < numRoots2; j++)
                {
                    if(abs(roots1[i] - roots2[j]) < ERROR_MARGIN)
                    {
                        sol->setX(roots1[i], index);
                        index++;
                    }
                }
            }
        }
//        sol->PrintSolution();
    }
}
Example #7
0
int main(int argc, char* argv[])
{
	ListNode* head = NULL;
	ListNode* tail = NULL;
	ListNode* newNode;

	int n;
	int k;
	cin >> k;
	cin >> n;
	while (n != -999999) {
		newNode = new ListNode(n);
		if (NULL == tail) {
			head = newNode;
			tail = newNode;
		} else {
			tail->next = newNode;
			tail = newNode;
		}
		cin >> n;
	}

    Solution solution;
	head = solution.rotateRight(head, k);
	tail = head;
	while (tail != NULL) {
		cout << tail->val << endl;
		tail = tail->next;
	}

    return 0;
}
int main() {
    TreeNode *node11 = new TreeNode(1), *node21 = new TreeNode(2), *node22 = new TreeNode(3);
    node11->left = node21, node11->right = node22;
    Solution solution = Solution();
    cout << solution.maxPathSum(node11) << endl;
    return 0;
}
int main()
{
Solution s;
vector<int>v;
s.maxProfit(v);
	return 0;
}
Example #10
0
int main(int argc, const char * argv[])
{
    Solution s;
    vector<int> v{2,2};
    std::cout << s.candy(v);
    return 0;
}
Example #11
0
int main()
{
	ListNode* test = new ListNode(3);
	test->next = new ListNode(4);
	test->next->next = new ListNode(5);
	test->next->next->next = new ListNode(6);
	test->next->next->next->next = new ListNode(7);
	test->next->next->next->next->next = test->next;
	ListNode* p = test;
	cout << "The linked list is: ";
	for (int i = 0; i < 15; i++)
	{
		cout << p->value << "->";
		p = p->next;
	}
	cout << "...\n";

	Solution s;
	bool result = s.hasCycle(test);

	if (result)
		cout << "There is a cycle in it! "<< endl;
	else
		cout << "There is not a cycle in it! " << endl;
	system("pause");
	return 0;
}
Example #12
0
int main() {
    Solution s;
    vector<int> v;
    /*
    v.push_back(1);
    v.push_back(3);
    v.push_back(-1);
    v.push_back(-3);
    v.push_back(5);
    v.push_back(3);
    v.push_back(6);
    v.push_back(7);
    */

    v.push_back(7);
    v.push_back(2);
    v.push_back(4);

    vector<int> result = s.maxSlidingWindow(v, 2);
    for(int i = 0; i <= result.size() - 1; i++) {
        cout << result[i] << endl;
    }

    return 0;
}
Example #13
0
int main()
{
    Solution s;
    //vector<int> a{1,0,1,0,0,2,2,0,0,1};
    vector<int> a{1,2,3};
    std::cout<<s.xorGame(a)<<std::endl;
}
int main(int argc, char const *argv[])
{
	Solution sl; 
	vector<int> num;
	vector<vector<int> > res;  
	num.push_back(-1);
	num.push_back(0);
	num.push_back(1);
	num.push_back(2);
	num.push_back(-1);
	num.push_back(-4);
	//num.push_back(1);
	//num.push_back(2);
	//num.push_back(3);
	//num.push_back(1);
	res = sl.fourSum(num, -1);
	for(auto it:res){
		for (int i = 0; i < it.size(); ++i)
		{
			cout<<"the result is "<<it[i]<<"    "; 
		}
		cout<<"another set"<<endl;
	}
	return 0;
}
int main()
{
    vector<vector<int>> input_vector;
    vector<int> row;
    //int input_array[SIZE][SIZE] = {{1}};
    int input_array[SIZE][SIZE] = {{1,2,3},{4,5,6},{7,8,9}};

    //将二维数组压入vector中
    for( int i = 0; i < SIZE; i++)
    {
        for(int j = 0; j < SIZE; j++)
        {
            //将每一行压入vector中
            row.push_back(input_array[i][j]);
        }
        //将vector压入总的vector中
        input_vector.push_back(row);
        //清空总的vector
        row.clear();
    }

    cout<<"矩阵反转前:"<<endl;
    print_vector(input_vector);

    cout<<"\n开始反转......"<<endl;
    //矩阵反转
    Solution s;
    s.rotate(input_vector);

    cout<<"\n矩阵反转后:"<<endl;
    print_vector(input_vector);
    return 0;
}
Example #16
0
int main (int argc, char const *argv[]){
	if (argc != 2)
	{
		std::cout << "Numero incorrecto de parametros" << std::endl;
		std::cout << "Usage: ./bacp instancia.txt" << std::endl;
		//Instance i = InstanceReader::read_instance("/home/leo137/Dev/bacp/informatica/bacp8.txt");
		//i.print_params();
		//SolverGA solverGA = SolverGA();
		//Solution s = solverGA.solve_instance(i);
		//s.show_solution();
		/*i = InstanceReader::read_instance("/home/leo137/Dev/bacp/informatica/bacp10.txt");
		s = solverGA.solve_instance(i);
		s.show_solution();*/
		/*i = InstanceReader::read_instance("/home/leo137/Dev/bacp/informatica/bacp12.txt");
		s = solverGA.solve_instance(i);
		s.show_solution();*/
		//i = InstanceReader::read_instance("/home/leo137/Dev/bacp/informatica/bacp10.txt");
		//s = solverGA.solve_instance(i);
		//s.show_solution();
	}
	else{
		Instance i = InstanceReader::read_instance(argv[1]);
		i.print_params();
		SolverGA solverGA = SolverGA();
		Solution s = solverGA.solve_instance(i);
		s.show_solution();
	}
	return 0;
}
Example #17
0
int main (int argc, char const *argv[])
{
	Solution s;
	string p("/home//foo");
	cout << s.simplifyPath(p);
	return 0;
}
Example #18
0
int main() {
  // std::string w = "ABCCED";
  // std::vector<std::vector<char>> b = {
  //   {'A', 'B', 'C', 'E'},
  //   {'S', 'F', 'C', 'S'},
  //   {'A', 'D', 'E', 'E'}
  // };
  std::string w = "a";
  std::vector<std::vector<char>> b = {
    {'a'}
  };
  // std::string w = "aaa";
  // std::vector<std::vector<char>> b = {
  //   {'a', 'a'}
  // };
  // std::string w = "AAB";
  // std::vector<std::vector<char>> b = {
  //   {'C', 'A', 'A'},
  //   {'A', 'A', 'A'},
  //   {'B', 'C', 'D'},
  // };
  Solution s;
  printf("%s\n", s.exist(b, w) ? "true" : "false");  
  return 0;
}
Example #19
0
int __tmain( )
{
    Solution solu;
    cout <<solu.JumpFloorII(2) <<endl;;

    return 0;
}
Example #20
0
int main(){
	Solution c;
	int A[] = {1,2,3,4};
	ListNode *head = NULL, *p = NULL;
	for(int i = 0; i < sizeof(A)/4; i++){
		ListNode *s = new ListNode(A[i]);
		if(head == NULL) head = p = s;
		else{
			p->next = s;
			p = s;
		}
	}
	p->next = NULL;
	p = head;
	while(p != NULL){
		cout << p->val << " ";
		p = p->next;
	}
	cout << endl;
	p = c.rotateRight(head, 3);
	while(p != NULL){
		cout << p->val << " ";
		p = p->next;
	}
	return 0;
}
Example #21
0
int main(int argc, char* argv[]){
	Solution sol;
	string start = "hit", end = "cog";
	unordered_set<string> dict = {"hot","dot","dog","log","lot"};
	cout << sol.ladderLength(start,end,dict) << endl;
	return 0;
}
Example #22
0
int main()
{
    ListNode *l1 = NULL;
    ListNode *l2 =NULL;
    ListNode n0(-10);
    ListNode n1(-10);
    ListNode n2(-9);
    ListNode n3(-4);
    ListNode n4(1);
    ListNode n5(6);
    ListNode n6(6);
    ListNode n7(-7);
    //ListNode n3(-4);
    l1 = &n0;
    n0.next = &n1;
    n1.next = &n2;
    n2.next = &n3;
    n3.next = &n4;
    n4.next = &n5;
    n5.next = &n6;
    l2 = &n7;

    Solution s;
    ListNode *l = s.mergeTwoLists(l1,l2);
    while(l!=NULL){
        cout<<l->val<<endl;
        l = l->next;
    }
    //cout <<flush<< c<< endl;
    return 0;
}
int
main()
{
  vector<vector<int> > grid = {{1,1,1}, {2,1,3},{0,0,0}};
  Solution solution;
  cout << solution.minPathSum(grid) << endl;
}
Example #24
0
int main()
{
    Solution sln;
    sln.generateParenthesis(3);
    system("pause");
    return 0;
}
int main()
{
	vector<Point> list = { Point(84, 250), Point(0, 0), Point(1, 0), Point(0, -70), Point(1, -1), Point(21, 10), Point(42, 90),
		Point(-42, -230) };
	Solution s;
	s.maxPoints(list);
}
Example #26
0
int main(int argc, const char * argv[]) {
    // insert code here...
    Solution so;
    int result = so.lengthOfLastWord(" ab ");
    cout<<result<<endl;
    return 0;
}
Example #27
0
int main() {
    Solution test;
    cout << test.intToRoman(16) << endl;
    cout << test.intToRoman(3999) << endl;

    return 0;
}
Example #28
0
int main(){
	string str = "PAYPALISHIRING";
	Solution s;
	string res = s.convert(str, 3);
	cout<<res<<endl;
	return 0;
}
Example #29
0
int main(int argc, const char * argv[]) {
    // insert code here...
    Solution so;
    string result = so.convertToTitle(78);
    cout<<result<<endl;
    return 0;
}
Example #30
0
int main(){
	vector<int> A; 
	// for(int i = 1; i < 4; i++){
	// 	A.push_back(i);
	// }
	A.push_back(1);
	A.push_back(2);
	A.push_back(2);
	//A.push_back(15);
	//A.push_back(1);

	vector<vector<int> >  out_put;
	Solution test;
	out_put = test.subSetDup(A);

	cout<<"Answer is: "<<"\n";
	cout<<"["<<endl;
	for(vector<vector<int> >::size_type i = 0 ; i < out_put.size(); i++){
		cout<<"  [";
		for(vector<int>::size_type j = 0; j < out_put[i].size();j++){
			std::cout<< out_put[i][j];
			if(j < out_put[i].size() - 1){
				cout<<" ";
			}
		}
		cout<<"]"<<"\n";
		// if(i < out_put.size() - 1){
		// 	cout<<", ";
		// }
	}
	cout<<"]" <<"\n"<<endl;
}