Simulation questions. Each cell has an expression on DFS, and if there is a ring then it cannot be parsed, and may be repeatedly accessed to unresolved cells, dropped sets, or the array is sentenced to repeat.
This problem first frame to, variable name do not take too messy, more details, know more library functions easier to write. Note the details and note the format.
/**********************************************************--------------Tyrannosaurus---------* * Author Abyssalfish ***********************************************************/#include<bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intR = -, C =Ten, LEN = the;structnode{intN; strings; BOOLTp//1 num 0 exprNode () {s.reserve (LEN);}} ND[R][C];intErr[r][c], KAS_CLK;voidREADND (intXinty) {Node&u =Nd[x][y]; Getline (CIN, U.S.); U.TP=!isalpha (u.s[0]);//-, 1, A if(U.TP) {StringStream ssin (U.S.); Ssin>>U.N; }}Const intErrorCode =1<< -; typedef pair<int,int>Pii;vector<pii >Un_ev;intVis[r][c], CLK;//ParsendintDfsintXinty) {Node&u =Nd[x][y]; if(U.TP)returnU.N; if(Err[x][y] = = KAS_CLK)returnErrorCode; if(Vis[x][y] = =CLK) {Err[x][y]=KAS_CLK; Un_ev.push_back (PII (x, y)); returnErrorCode; } Vis[x][y]=CLK; intAns =0, Sz =u.s.size (); //stack<char> Stk; for(inti =0; I < sz; i++){ if(Isalpha (U.s[i])) {intval = dfs (u.s[i]-'A', u.s[i+1]-'0'); if(val = =ErrorCode) { if(Err[x][y]! =KAS_CLK) {Err[x][y]=KAS_CLK; Un_ev.push_back (PII (x, y)); } returnErrorCode; } CharOP = i?u.s[i-1]:'+';//stk.top (); Stk.pop ();Ans + = op=='+'? val:-Val; I++; } Else if(IsDigit (U.s[i])) {intj = i+1; whileJ < sz && IsDigit (U.s[j]) J + +; intval =atoi (U.s.substr (i,j). C_STR ()); Ans+ = u.s[i-1]=='+'? val:-Val; I= J1; } //if (s[i] = = ' + ' | | s[i] = = '-') {//}} u.tp=true; returnU.N =ans;}voidinit () {Un_ev.reserve (R*C);}intr,c;voidsolve () { for(inti =0; I < R; i++){ for(intj =0; J < C; J + +) {readnd (i,j); }} KAS_CLK++; for(inti =0; I < R; i++) for(intj =0; J < C; J + +){ if(Err[i][j]! =KAS_CLK) {CLK++; DFS (I,J); } } if(Un_ev.size ()) {sort (Un_ev.begin (), Un_ev.end ()); //un_ev.erase (Unique (Un_ev.begin (), Un_ev.end ()), Un_ev.end ()); for(Auto P:un_ev) {intx = p.first, y =P.second; printf ("%c%c:%s\n", x+'A', y+'0', Nd[x][y].s.c_str ()); } un_ev.clear (); } Else{Putchar (' '); for(intj =0; J < C; J + +) printf ("%6d", J); Puts (""); for(inti =0; I < R; i++) {Putchar (i+'A'); for(intj =0; J < C; J + +) {printf ("%6d", ND[I][J].N); } puts (""); }} puts ("");//Note Format}//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif //Ios::sync_with_stdio (FALSE); //Cin.tie (nullptr);init (); while(SCANF ("%d%d\n", &r,&c), r+c) {Solve (); } return 0;}
UVA 215 Spreadsheet Calculator