analog/String processing uvalive 6833 Miscalculatio

Source: Internet
Author: User

Topic Portal

1 /*2 Simulation/String processing: mainly on the processing of *, first the multiplication after preprocessing and then with the addition, for example: 1+2*3+4 = 1+. 6+4 = One3 */4#include <cstdio>5#include <algorithm>6#include <cstring>7#include <string>8#include <cmath>9#include <vector>Ten#include <map> One#include <queue> A using namespacestd; -  -typedefLong Longll; the Const intMAXN = 1e2 +Ten; - Const intINF =0x3f3f3f3f; - CharS[MAXN]; - intLen; +  - voidSolvevoid) + { A     intP1 =0, p2 =0; at      for(intI=1; i<=len; ++i) -     { -         if(S[i] = ='*') -         { -P1 = P2 =i; -              while(P1 >=1&& S[P1]! ='+') p1--; p1++; in              while(P2 <= len && s[p2]! ='+') p2++; p2--; -ll tmp =0; to              for(intJ=P1; j<=p2; j+=2) +             { -                 if(j = = p1) tmp = S[j]-'0'; the                 ElseTMP = TMP * (S[j]-'0'); *             } $ //printf ("P1:%d P2:%d\ntmp:%d\n", p1, p2, tmp);Panax Notoginseng             intp =P2; -              while(TMP) the             { +s[p--] = tmp%Ten+'0'; ATMP/=Ten; the             } +              for(intJ=P1; j<=p; ++J) S[j] ='.'; -         } $     } $ } -  - intMainvoid)//uvalive 6833 miscalculation the { - //freopen ("b.in", "R", stdin);Wuyi  the      while(SCANF ("%s", S +1) ==1) -     { Wull y; scanf ("%lld", &y); -ll sum_l =0, sum_m =0; About  $Len = strlen (S +1);CharOpintx =0; -          for(intI=1; i<=len; ++i) -         { -             if(I &1) A             { +                 if(i = =1) sum_l = S[i]-'0'; the                 Else -                 { $                     if(OP = ='+') sum_l + = S[i]-'0'; the                     Elsesum_l = sum_l * (S[i]-'0'); the                 } the             } the             ElseOP =S[i]; -         } in  the solve (); the          for(intI=1; i<=len; ++i) About         { the             if(S[i] = ='.'|| S[i] = ='+')Continue; the             Else if(S[i] >='0'&& S[i] <='9') the             { +ll res =0;intJ; -                  for(j=i; j<=len; + +)j) the                 {Bayi                     if(S[j] = ='+') Break; theres = res *Ten+ (S[j]-'0'); the                 } -Sum_m + =Res; -i = J-1; the             } the         } the  the         if(y = = sum_l && y = = sum_m) puts ("U"); -         Else if(Y! = sum_l && y! = sum_m) puts ("I"); the         Else the         { the             if(y = = sum_l) puts ("L");94             ElsePuts ("M"); the         } the  the //printf ("%s\n", S + 1);98 //printf ("%lld%lld \ n", sum_l, sum_m); About     } - 101     return 0;102}

analog/String processing uvalive 6833 Miscalculatio

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.