[ create a new paste ] login | about

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

hoaithu.melody - C++, pasted on May 28:
//tinh bieu thuc cay nhi phan
#include <iostream>
#include <conio.h>

using namespace std;

int N;

int main()
{
	int test_case;
	freopen("testcase.txt", "r", stdin);
	for(test_case = 1; test_case <= 10; ++test_case)
	{
		int i;
		int Number[1001] = { 0 }, Firstchild[1001] = { 0 }, Secondchild[1001] = { 0 };
		char Operator[1001] = { 0 };

		cin >> N;
		int max;
		for(i = 0; i < N; i++)
		{
			int addr;
			char buf[10];
			cin >> addr;
			cin >> buf;
			if ((buf[0] == '+') || (buf[0] == '-') || (buf[0] == '*') || (buf[0] == '/'))
			{
				Operator[addr] = buf[0];
				cin >> Firstchild[addr] >> Secondchild[addr];
				max = addr;
			}
			else 
			{
				int count = 0, num = 0;
				while(buf[count+1] != '\0')
					count++;
				num = buf[count] - '0';
				for(int j = 0; j < count; j++)
				{
					int temp = buf[j] - '0';
					int k = count - j;
					while(k > 0)
					{
						temp = temp * 10;
						k--;
					}
					num += temp;
				}
				Number[addr] = num;
			}
		}
		
		for(i = max; i >=1; i--)
		{
			if(Operator[i] == '+')
				Number[i] = Number[Firstchild[i]] + Number[Secondchild[i]];
			if(Operator[i] == '-')
				Number[i] = Number[Firstchild[i]] - Number[Secondchild[i]];
			if(Operator[i] == '*')
				Number[i] = Number[Firstchild[i]] * Number[Secondchild[i]];
			if(Operator[i] == '/' && Number[Secondchild[i]] != 0)
				Number[i] = Number[Firstchild[i]] / Number[Secondchild[i]];
		}
		
		cout << "#" << test_case;
		cout << " " << Number[1] << endl;
	}
	getch();
	return 0;
}


Output:
1
2
3
4
Line 18: error: conio.h: No such file or directory
In function 'int main()':
Line 69: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: