zoukankan      html  css  js  c++  java
  • ACM-ICPC TOKYO 2014 B Miscalculation

    题意:给你一个算式,问你乘法优先 和 从左到右计算的答案。

    解题思路:水+乱搞

    解题代码:

      1 // File Name: b.cpp
      2 // Author: darkdream
      3 // Created Time: 2015年03月25日 星期三 12时32分43秒
      4 
      5 #include<vector>
      6 #include<list>
      7 #include<map>
      8 #include<set>
      9 #include<deque>
     10 #include<stack>
     11 #include<bitset>
     12 #include<algorithm>
     13 #include<functional>
     14 #include<numeric>
     15 #include<utility>
     16 #include<sstream>
     17 #include<iostream>
     18 #include<iomanip>
     19 #include<cstdio>
     20 #include<cmath>
     21 #include<cstdlib>
     22 #include<cstring>
     23 #include<ctime>
     24 #define LL long long
     25 
     26 using namespace std;
     27 char str[1000];
     28 int tt;
     29 int a[100];
     30 int op[100];
     31 int m ;
     32 int solve1()
     33 {
     34      int ta[100];
     35      int tp[100];
     36      memcpy(ta,a,sizeof(a));
     37      memcpy(tp,op,sizeof(op));
     38      int tk = tt; 
     39      int ok = 0; 
     40      while(!ok)
     41      {
     42          ok = 1; 
     43          for(int i = 1;i < tk ;i ++)
     44          {
     45            if(tp[i] == 2 )
     46            {
     47               ok = 0 ; 
     48               ta[i] = ta[i]*ta[i+1];
     49               for(int j = i+2;j <= tk ;j ++)
     50               {
     51                   ta[j-1] = ta[j];
     52                   tp[j-2] = tp[j-1];
     53               }
     54               tk -- ; 
     55               break;
     56            }
     57          }
     58      }
     59      int ans = ta[1];
     60      for(int i = 1;i < tk;i ++)
     61      {
     62         if(tp[i] == 1) 
     63             ans += ta[i+1];
     64         else ans *= ta[i+1];
     65      }
     66      //printf("%d
    ",ans);
     67      if(ans == m )
     68          return 1; 
     69      return 0 ;
     70      
     71 }
     72 int solve2()
     73 {
     74      int ans = a[1];
     75      for(int i = 1;i < tt;i ++)
     76      {
     77         if(op[i] == 1) 
     78             ans += a[i+1];
     79         else ans *= a[i+1];
     80      }
     81      //printf("%d
    ",ans);
     82      if(ans == m )
     83          return 1; 
     84      return 0 ;
     85 }
     86 int main(){
     87     scanf("%s",str);
     88     scanf("%d",&m);
     89     int len = strlen(str); 
     90     int t = 0 ;
     91     tt = 0 ; 
     92     for(int i = 0 ;i < len ;i ++)
     93     {
     94         if(str[i] <= '9' && str[i] >= '0')    
     95         {
     96            t = t * 10 + str[i] - '0' ;   
     97         }else{
     98            tt ++ ;
     99            //printf("***
    ");
    100            if(str[i] == '+')
    101              {
    102                op[tt] = 1;
    103              }else op[tt] = 2; 
    104            a[tt] = t ;
    105            t = 0 ;
    106         }
    107     }
    108     tt ++ ; 
    109     a[tt] = t;
    110     int tt1 = solve1();
    111     int tt2 = solve2();
    112     if(tt1&& tt2)
    113     {
    114        puts("U");
    115     }else if(tt1)
    116     {
    117        puts("M");
    118     }else if(tt2)
    119         puts("L");
    120     else puts("I");
    121 return 0;
    122 }
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    asp.net 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction
    mvc EF 执行SQL语句
    MVC 自定义AuthorizeAttribute实现权限管理
    EF
    sql 、linq、lambda 查询语句的区别
    说说C#中的enum吧
    C# A窗口内容显示在B窗口中的方法
    C# 程序开始主要是写类和方法 的基本步骤和调用方法
    C# 文件流基本操作步骤
    Ghost命令使用方法
  • 原文地址:https://www.cnblogs.com/zyue/p/4366983.html
Copyright © 2011-2022 走看看