[C++] Parenthesis checker [Code_Problem]

PROBLEM : Given an expression string exp. Examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp. For example, the program should print 'balanced' for exp = “[()]{}{[()()]()}” and 'not balanced' for exp = “[(])” Input: The first line of input contains an integer T denoting the number of test cases.  Each … Continue reading [C++] Parenthesis checker [Code_Problem]

[CodeChef Problem] Beautiful Arrays Problem Code: ICPC16B

#include<iostream> using namespace std; int main() { int i,t=0; int T,n; cin>>T; string result[T]; do{ int zero=0,one=0,min_one=0,other_num=0; cin>>n; int a[n]; for(i=0;i<n;i++) { cin >> a[i]; if(a[i]==1) one++; else if(a[i]==0) zero++; else if(a[i]==-1) min_one++; else other_num++; } result[t] = ((other_num > 1) || (min_one > 1 && one == 0) || (min_one > 0 && other_num … Continue reading [CodeChef Problem] Beautiful Arrays Problem Code: ICPC16B

[CodeChef Problem] Snake Procession

The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he sees a snake first, it'll be its Head, and hence he will mark a 'H'. The snakes are long, and when he sees the snake finally slither away, he'll mark a 'T' to denote its tail. In the time in between, when the snake is moving past him, or the time between one snake and the next snake, he marks with '.' s.