#include <iostream>
using namespace std;
int atoi(char *a)
{
int res = 0;
for(int i = 0; a[i] != '\0';i++)
{
res = res*10 + a[i] - '0';
}
return res;
}
int main(int argc, char** argv)
{
int N;
int Firstchild[1001]={0}, Secondchild[1001]={0}, Num[1001]={0};
char Oper[1001]={'\0'};
int test_case;
freopen("input.txt","r",stdin);
for(test_case = 1; test_case <= 10; ++test_case)
{
int ans;
cin >> N;
for(int i = 0; i < N; i++)
{
int addr;
char buf[10];
cin >> addr;
cin >> buf;
if( buf[0] == '+'|| buf[0]== '-' || buf[0] == '*' || buf[0] == '/' )
{
Oper[addr] = buf[0];
cin >> Firstchild[addr];
cin >> Secondchild[addr];
}
else
Num[addr] = atoi(buf);
}
for(int i = N; i >0; i--)
{
char oper = Oper[i];
if (oper != 0 )
{
int lf= Num[Firstchild[i]];
int rf= Num[Secondchild[i]];
if( oper =='+')
Num[i] = lf + rf;
else if(oper == '-')
Num[i] = lf - rf;
else if(oper =='*')
Num[i]= lf*rf;
else Num[i] = lf/rf;
Oper[i] = 0;
}
}
cout << "#" << test_case << " " << Num[1] << endl;
/////////////////////////////////////////////////////////////////////////////////////////////
/*
이 부분에 여러분의 알고리즘 구현이 들어갑니다.
*/
/////////////////////////////////////////////////////////////////////////////////////////////
}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.