/* <Br/> This is a lecture by Hu daniu. <br/> orz <br/> */<br/> # include <iostream> <br/> # include <sstream> <br/> # include <map> <br/> # include <string> <br/> using namespace STD; <br/> Map <string, int> DF; <br/> int main () <br/>{< br/> int T; <br/> CIN> T; <br/> while (t --) <br/>{< br/> int N; <br/> CIN> N; <br/> string a, B; <br/> int C; <br/> DF. clear (); <br/> for (INT I = 1; I <n; I ++) <br/>{< br/> CIN> A> B> C; <br/> DF [A] = C; <br/>}< br/> string STR; <br/> getchar (); // receives the carriage return <br/> Getline (CIN, STR ); <br/> stringstream SS (STR); // defines the input stream <br/> string str1; <br/> int Sign = 1; <br/> int sum = 0; <br/> while (SS> str1) <br/>{< br/> If (str1 = "-") <br/>{< br/> Sign =-1; <br/>}< br/> If (str1 = "+ ") <br/>{< br/> Sign = 1; <br/>}< br/> If (str1 = "= ") <br/>{< br/> break; <br/>}< br/> If (isalpha (str1 [0]) // determine whether it is a letter <br/>{< br/> If (DF. Find (str1 )! = DF. end () <br/>{< br/> sum + = DF [str1] * sign; <br/>}< br/> else <br/> {<br/> int temp; <br/> temp = atoi (str1.c _ STR (); // convert to Char and convert it to int <br/> sum + = temp * sign; <br/>}< br/> cout <sum <Endl; <br/>}< br/>}