|
|
вернуться в форумWA 27 Послано Sunnat 20 май 2014 19:02 what's wrong in my code, please give me some test #include <iostream> #include <vector> #include <string> #include <map> using namespace std; map<string,string>functions; map<string,string>variables; int main(){ int count_function, count_variable,i,j; string line,s1,s2,s, type; cin >> count_function; for(i = 0; i < count_function; i ++){ cin >> s1; while(cin >> s){ if(s == ":") break; s1 = s1 + " " + s; } cin >> s2; functions[s1] = s2; }
cin >> count_variable;
vector<string>variable; vector<string>types;
for(i = 0; i < count_variable; i ++){ cin >> type >> s >> s1 >> s1; while(s1[s1.size() - 1] != ')'){ cin >> s2; s1 = s1 + " " + s2; } if(variables.find(s) == variables.end()){ s2 = ""; j = 0; while(s1[j] != '(') s2 += s1[j++]; s2 += '('; j ++; while(s1[j] != ')'){ line = ""; while(s1[j] != ',' && s1[j] != ')') line += s1[j++]; if(variables.find(line) == variables.end()){ cout << "Error on line " << i + 1 << ": " << "Unknown variable" << endl; return 0; } s2 += variables[line]; if(s1[j] == ','){ s2 += ", "; j += 2; } } s2 += ')';
if(functions.find(s2) == functions.end()){ cout << "Error on line " << i + 1 << ": " << "No such function" << endl; return 0; }
s2 = functions[s2];
if(type == "auto"){ variable.push_back(s); types.push_back(s2); type = s2; } if(type != s2){ cout << "Error on line " << i + 1 << ": " << "Invalid initialization" << endl; return 0; } variables[s] = s2; }else{ cout << "Error on line 2: Double declaration" << endl; return 0; } } for(i = 0; i < types.size(); i ++) cout << variable[i] << " : " << types[i] << endl; return 0; } |
|
|