int main(void){
	Solution answer;
	cout << answer.longestValidParentheses("(()()))") << endl;
	cout << answer.longestValidParentheses("(()((()())") << endl;
	cout << answer.longestValidParentheses(")()(()") << endl;
	system("Pause");
	return 0;
}
int main(int argc, const char *argv[]) {
    Solution solution;
    
    std::cout << solution.longestValidParentheses(")()()") << std::endl;
    std::cout << solution.longestValidParentheses("()()") << std::endl;
    std::cout << solution.longestValidParentheses("(()") << std::endl;
    
    return 0;
}
int main() {
    Solution sol;
    cout << sol.longestValidParentheses("(()") << endl;
    cout << sol.longestValidParentheses("()()") << endl;
    cout << sol.longestValidParentheses("()(()") << endl;
    cout << sol.longestValidParentheses("(()()") << endl;
    cout << sol.longestValidParentheses("())()") << endl;
    cout << sol.longestValidParentheses(")()()") << endl;
    return 0;
}
int main(int argc, char *argv[]) {
    Solution sol;
    {
        cout << sol.longestValidParentheses("()()") <<endl;
    }
    {
        cout << sol.longestValidParentheses("()(()") <<endl;
    }
    {
        cout << sol.longestValidParentheses(")(") <<endl;
    }
    return 0;
}
int main() {
    Solution test;

    string s1 = "(()";
    cout << test.longestValidParentheses(s1) << endl;

    string s2 = ")()())";
    cout << test.longestValidParentheses(s2) << endl;

    string s3 = "()(())()()())((()))())((())()(())((()()()()(()()()))))))(()))()(())()(((()()(((()()()(((())))((())(()((()())())()(()(()(((())()()))())((())()(((())()()))))()(((()()))()()))(((()))(((())))())())(";
    cout << test.longestValidParentheses(s3) << endl;

    return 0;
}
int main() {
    Solution s;
    cout << s.longestValidParentheses("") << endl;
    cout << s.longestValidParentheses(")(") << endl;
    cout << s.longestValidParentheses("()(") << endl;
    cout << s.longestValidParentheses("())(") << endl;
    cout << s.longestValidParentheses("()") << endl;
    cout << s.longestValidParentheses(")()())") << endl;
    cout << s.longestValidParentheses("()((((()()()((()()") << endl;
    cout << s.longestValidParentheses(")()()(()()()))()") << endl;
    cout << s.longestValidParentheses("(()))((((())()()((()()()))()())") << endl;
}
Example #7
0
int main() {
	Solution s;
	int len = s.longestValidParentheses("(((()))))((()))");
	cout<<len<<endl;
	system("pause");
	return 0;
}
Example #8
0
int main()
{
    Solution SO;
    string s ="())";
    cout<<s<<endl;
    cout<<SO.longestValidParentheses(s);
}
int main() {
    Solution sln;

    cout << sln.longestValidParentheses("()(())") << endl;

    return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
    string s = ")((()))())(())())(";
    Solution so;
    so.longestValidParentheses(s);

	return 0;
}
Example #11
0
int main() {
    Solution sol;
    string s;
    cin >> s;
    cout << sol.longestValidParentheses(s) << endl;

    return 0;
}
int main(){
	string s = "(((())(()(";
	Solution sol;
	cout << sol.longestValidParentheses(s) << endl;


	return 0;
}
int main()
{
    string str;
    cin >> str;
    Solution solution;
    cout << solution.longestValidParentheses(str) << endl;
    return 0;
}
int main() {
    ofstream fout("sol.out");
    ifstream fin("sol.in");

    Solution sol;
    cout << sol.longestValidParentheses("(()") << endl;
    return 0;
}
int main(int argc,char **argv){
    Solution s;
    while(true){
        string ss;
        cin >> ss;
        cout << ss << ":" << s.longestValidParentheses(ss) << endl;
    }
}
int main() {
    Solution solution;
    string input = "())()()(())((()(()()(((()))((((())((()(())()())(()((((()))()(()))(())()(())(()(((((())((((((()())())(()(()((())()))(()))))))()(()))((((())()()()))()()()(((()(()())(()()(()(()()(((()))))))()()))())())((()()))))))((()))(((()((())()(()()))((())))()()())))))))()))))(()))))()))()))()((())))((()))(()))))))(((()))))))))()(()()()(())((())()))()()(())))()()))(()())()))(((()())()))((())((((()))(()(()(()()()(((())()(((((()))((()(((((())(()()))((((((((()(()(()(()(())))(())(()())())(()((((()(())((()(())))(())))()(((((()(()()(())))))))())(())(())(()()(((())))((()))(((((()))))())))()((()))()))))())))))((())(((((()()))((((())))(((()(()(())())(((()(()(()()()())))())()))((()((())())()()()(((())(((((()((((((()((()())))((((())((()(((((((()(()((()()()(()(()())(()(()()((((())))()(((()())))(()()))()(()()()()(((((())(()))))((()))())))()((((((()))())))()(()))(())))((((()())(((((()()())(((((())(()())(()))))()(()()))()))))))())))(((())(()(()()))(()))()(((())))())((((()(((()))))))()(()(()))()()(()()))))))))((()))))))(())((()((()))()))((((((()())))))(()((())((((()))))(()(()()()()(()))()()(()(()))(()()(((((((()())(())(()())((())())()(()())((())()())())(()())))())))(())())())(())((()())(((()()))()))()()))()(()(())((((((((())))()((())((()((((((((((()))))(()(((((())(()(()())())))((())())))))()))(()((()()))((()((())()()()((()(())())((())())(()()(((())))))())()()(()))()())(()(()((())))((((()()(())))())(())(()(()(())())())(()()())()(())())))(()()(((())))((()()(((())()()(()())((((()()(()())(()((((()(()()(()(()(((()((()())(()()))(()((((()(((((()))))()()))(((()((((((()(()()()()())()))(()(())))))((()(((()())())))(((()()))(()(()(((((((()()))(()(())))())()(())())(())(()))(())(()))()()(()()())))))()))()((())(((()((((((((())()()))())))((()())(";
    cout << input << endl;
    int result = solution.longestValidParentheses(input);
    cout << result << endl;
    return 1;
}
int main()
{
	//string s = ")()())()";
	//string s = ")()())()(()())))";
	string s = "()(()";
	Solution solution;
	cout << solution.longestValidParentheses(s);

	system("pause");
	return 0;
}
int main() {

	string s = ")()())()())";
	Solution solution;
	cout << solution.longestValidParentheses(s) << endl;
	Solution1 solution1;
	Solution2 solution2;
	cout << solution1.longestValidParentheses(s) << endl;
	//cout << solution2.longestValidParentheses(s) << endl;
	return 0;
}
int main(void) {
	Solution *s = new Solution();
	string s1 = "(()";
	string s2 = ")()())";
	
	cout << "Solution 1: " << s->longestValidParentheses(s1) << endl;
	cout << "Solution 1: " << s->longestValidParentheses(s2) << endl;
	
	delete s;
	return 0;
}
static void test_func(string &ss, int expect)
{
	Solution s;
	int ret = s.longestValidParentheses(ss);

	cout << "The longest parentheses of " << ss << "is " << ret;
	if (ret != expect) {
		cout << ", not expected!!!";
	}
	cout << endl;

}
int main() {
#ifdef LOCAL
    freopen("/Users/apple/input.txt","r",stdin);
    //	freopen("/Users/apple/out.txt","w",stdout);
#endif
	Solution cc;
	string s;
	cin >> s;
	cout << cc.longestValidParentheses(s) << endl;

	return 0;

}
Example #22
0
int main()
{
	int src[][3]=
	{
	{9,9,0},
	{1,0,5},
	{2,5,6}
	};
	string start("hit");
	string end=("cog");
	string dict1[]={"hot","dot","dog","lot","log"};


	//s.ladderLength(start,end,dict);
	Solution s;
	cout<<s.longestValidParentheses("(()))())()()())()())(")<<endl;
	return 0;
}
int main() {
	Solution s;
        cout<<s.longestValidParentheses(")()())")<<endl;
	return 0;
}
int main(){
	string s="()";
	Solution a;
	cout<<a.longestValidParentheses(s);
}
int main() {
    Solution s;
    cout<<s.longestValidParentheses("()()")<<endl;
	system("pause");
	return 0;
}
int main(){
    Solution s;
    cout<<(s.longestValidParentheses("")==0)<<endl;
    cout<<(s.longestValidParentheses("(")==0)<<endl;
    cout<<(s.longestValidParentheses(")")==0)<<endl;
    cout<<(s.longestValidParentheses("))")==0)<<endl;
    cout<<(s.longestValidParentheses(")(")==0)<<endl;
    cout<<(s.longestValidParentheses("(()")==2)<<endl;
    cout<<(s.longestValidParentheses("(()()")==4)<<endl;
    cout<<(s.longestValidParentheses("(()())")==6)<<endl;
    cout<<(s.longestValidParentheses("(()()(")==4)<<endl;
    cout<<(s.longestValidParentheses("(())")==4)<<endl;
    cout<<(s.longestValidParentheses(")()")==2)<<endl;
    cout<<(s.longestValidParentheses(")())")==2)<<endl;
    cout<<(s.longestValidParentheses(")()()")==4)<<endl;
    cout<<(s.longestValidParentheses(")()()(")==4)<<endl;
    cout<<(s.longestValidParentheses(")()(())")==6)<<endl;
    cout<<(s.longestValidParentheses(")()(())()")==8)<<endl;
    cout<<(s.longestValidParentheses("(()))")==4)<<endl;
    cout<<(s.longestValidParentheses("(()")==2)<<endl;
    cout<<(s.longestValidParentheses("((())")==4)<<endl;
    cout<<(s.longestValidParentheses("()(")==2)<<endl;
    cout<<(s.longestValidParentheses("((()(")==2)<<endl;
    cout<<(s.longestValidParentheses("((()()")==4)<<endl;
    cout<<(s.longestValidParentheses("((()(()")==2)<<endl;
    cout<<(s.longestValidParentheses("()()))))()()(")==4)<<endl;
}
Example #27
0
int main(int argc, char *argv[]){
	Solution sol;
	string s(argv[1]);
	cout << sol.longestValidParentheses(s) << endl;
	return 0;
}
                candidate = 0;
            }
        }
        ans = max(ans, candidate);

        return ans;
    }
};


#ifdef RUN_TEST
TEST_CASE("32. Longest Valid Parentheses") {
    Solution s;

    string str = "(()";
    CHECK(s.longestValidParentheses(str) == 2);
    CHECK(str == "(..");

    str = ")()())";
    CHECK(s.longestValidParentheses(str) == 4);
    CHECK(str == ")....)");

    str = ")(()()))";
    CHECK(s.longestValidParentheses(str) == 6);
    CHECK(str == ")......)");

    str = "))()()))((()))(()";
    CHECK(s.longestValidParentheses(str) == 6);
    CHECK(str == "))....))......(..");

    str = string(100000, '(') + string(100000, ')');
Example #29
0
int main() {
	Solution s;
	s.longestValidParentheses(")()())");
}
Example #30
0
/*class Solution {
public:
    int c(char a){
        if(a=='('){
            return -1;
        }
        else if(a==')'){
            return 1;
        }
    }
    int longestValidParentheses(string s) {
        
        int ret=0;
        int len=s.length();
        int **dp=new int*[len];
        for(int i=0;i<len;i++){
            dp[i]=new int[len];
        }
        for(int i=0;i<len;i++){
            dp[i][i]=c(s[i]);
        }
        for(int i=0;i<len;i++){
            for(int j=i+1;j<len;j++){
                if(dp[i][j-1]==1 and c(s[j])==-1){
                    for(int x=j;x<len;x++){
                        dp[i][len-1]=1;
                    }
                  
                  break;
                }
                else{
                    dp[i][j]=dp[i][j-1]+c(s[j]);
                }
            }
        }
        for(int i=0;i<len;i++){
            for(int j=i+1;j<len;j++){
                if(dp[i][j]==0){
                    if(j-i>ret){
                        ret=j-i;
                    }
                }
                
            }
        }
        return ret;
        
    }
};*/
int main(){
    Solution s;
    s.longestValidParentheses(")()())()()(");
    return 0;
}