Demo entry 3548905

9012

   

Submitted by anonymous on Jan 20, 2016 at 06:40
Language: C++. Code size: 680 Bytes.

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	int count = 0;
	scanf("%d", &count);
	std::string temp ="";

	for (int i = 0; i < count; ++i) {
		int k = 0;
		std::cin >> temp;
		char * ctemp = new char[temp.length() + 1];
		std::strcpy (ctemp, temp.c_str());

		for (int j = 0; j < temp.length(); ++j) {
			if (ctemp[j] == '(') {
				++k;
			}
			else if (ctemp[j] == ')') {
				--k;
			}
			if (k < 0) {
				j = temp.length();
			}
		}
		if (k == 0) std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).