|
|
Please, somebody provide with test case ... Check for "Invalid initialization" case. Edited by author 09.08.2018 20:10 Can anybody tell something for wa6? Edited by author 29.10.2011 23:21 Maybe this test can help you! 3 ReadString() : string ReadReal() : real RealToString(real) : string 3 string s = ReadString() real r = ReadReal() auto k = RealToString(r) "The interpreter must check EACH LINE of the main program searching for the following errors". Edited by author 21.06.2013 02:12 Which means that lines have a priority, not types of errors. Say, the program has 1st type of error in line 10, and 2nd + 4th types of error in line 2. When i had WA20, i checked for each of 4 types of errors in that order, and if i found one, i wrote it and finished my program (in this case, outputting error in line 10). Instead, you should check for all 4 types of errors in all lines, and output an earliest line in which an error occurs. And if several errors occur in that earliest line, then you should output an error with higher priority. Thus for case above, you should output 2nd error type in line 2. 3 a() : int a(int) : real a(real) : int 3 int x = a() auto y = a(x) auto z = a(y) WA14 program says Error on line 3: No such function But right answer is y : real z : int 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; } In one line more then one error. 1 ReadInt2() : int ReadInt(int) : int 2 int x = ReadInt2() int x = ReadInt(y) My prog passes all tests what I found, but still WA1. Surely, output format is right. Sorry, stupid fault, forgot to delete extra lines of code. Got AC :) But why too few AC solutions? Problem is so easy. Edited by author 08.05.2012 22:47 Could anyone tell me the test 7? thx === just AC it ..= = Edited by author 27.03.2012 11:45 What's test 14? Try something like: 3 a() : real a(real) : int a(int) : real 3 auto b = a() int c = a(b) auto d = a(c) Output should be: b : real d : real Can anyone help with test 4? 1 Sum(int) : int; 1 int s = Sum(s) Ans : "Error on line 1: Unknown variable" Edited by author 09.11.2011 17:27 Thank you very much! I didn't notice this testcase earlier and got AC with your help! What is WA 4? 1 SumRealInt(real, int) : real 1 auto x = SumRealInt(c, v) Answer: Error on line 1: Unknown variable My program passed your test but it stills get WA4. Do you have any more? UPD: At last I solved it. See neighbour topic for help ;) Edited by author 10.11.2011 18:19 Edited by author 10.11.2011 18:19 |
|
|