UVA 215 Spreadsheet Calculator

Source: Internet
Author: User
Tags define local

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.