[ create a new paste ] login | about

Link: http://codepad.org/uPnPZdZH    [ raw code | output | fork ]

yifan666 - C, pasted on Aug 10:
//PairingParentheses

#include <stdio.h>
#include <iostream>

using namespace std;
int Qx[1000];

int f;

void init(){
	f=0;
}

void push(int x){
	f= f+1;
	Qx[f] = x;
	
}
int valueInf(){
	return Qx[f];
}

void pop(){
	f = f-1;
//	x=Qx[f];

}
int change(char c){
	if(c == '(') return -1; 
	if(c == ')') return 1; 
	if(c == '[') return -2; 
	if(c == ']') return 2; 
	if(c == '{') return -3; 
	if(c == '}') return 3; 
	if(c == '<') return -4;
	if(c == '>') return 4;  
}

int main(){

	int N, i, test_case, j, x, y;

	
	freopen("PairingParentheses.txt", "r", stdin);
	
	for(test_case=1; test_case<11; test_case++){
		
		cin >> N;
		cin.ignore();
		char c[N];
		int k;
		for (int i=0;i<N;i++)
			cin>>c[i];
		init();	

//		for (int i=0;i<N;i++)
//			cout<<c[i];
			
		
		for(int i=0; i<N; i++){
			k = change(c[i]);
	//		printf("f %d   k = %d  valueInf() = %d\n", f, k, valueInf());

			if(i == 0){
				push(k);
			}
			else{		
				if((k + valueInf())==0){
					pop();
				}else 
				if((k + valueInf())!=0){
					push(k);
				}		
			}	
		}
		
		if(f<=0)
			printf("#%d 1\n", test_case);
		else
			printf("#%d 0\n", test_case);
	}
	return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
Line 19: error: iostream: No such file or directory
Line 6: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'
In function 'main':
Line 49: error: 'cin' undeclared (first use in this function)
Line 49: error: (Each undeclared identifier is reported only once
Line 49: error: for each function it appears in.)
Line 53: error: 'for' loop initial declaration used outside C99 mode
Line 61: error: redefinition of 'i'
Line 53: error: previous definition of 'i' was here
Line 61: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: