zoukankan      html  css  js  c++  java
  • ZOJ 3782 G

    LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782

    题意:给出3个数和两个符号(+-*/%)

    思路:拿到题目还以为是要写波兰表达式,仔细一看固定的数和固定的符号,直接if判断好了

    /** @Date    : 2017-03-23-21.31
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version :
      */
    #include<bits/stdc++.h>
    #define LL long long
    #define PII pair
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    
    int main()
    {
        int T;
        cin >> T;
        while(T--)
        {
            int a, b, c;
            char o1[2], o2[2];
            int t = 0, ans = 0;
            scanf("%d %s%d %s%d", &a, o1, &b, o2, &c);
            //cout << a << o1 << b << o2 << c << endl;
            if(o1[0] != '*' && o1[0] != '/' && o1[0] != '%' && o2[0] != '+' && o2[0] != '-')
            {
                if(o2[0] == '*')
                    t = b * c;
                else if(o2[0] == '/')
                    t = b / c;
                else if(o2[0] == '%')
                    t = b % c;
                if(o1[0] == '+')
                    t = a + t;
                else if(o1[0] == '-')
                    t = a - t;
            }
            else
            {
                if(o1[0] == '+')
                    t = a + b;
                else if(o1[0] == '-')
                    t = a - b;
                else if(o1[0] == '*')
                    t = a * b;
                else if(o1[0] == '/')
                    t = a / b;
                else if(o1[0] == '%')
                    t = a % b;
    
                if(o2[0] == '+')
                    t = t + c;
                else if(o2[0] == '-')
                    t = t - c;
                else if(o2[0] == '*')
                    t = t * c;
                else if(o2[0] == '/')
                    t = t / c;
                else if(o2[0] == '%')
                    t = t % c;
            }
            //cout << 5 % 8 % 2 << endl;
            printf("%d
    ", t);
        }
        return 0;
    }
    
    
  • 相关阅读:
    UOJ309 UNR #2 排兵布阵
    BZOJ4860: [Beijing2017]树的难题
    CQOI2017 部分题解
    SDOI2017 Round1 Day2 题解
    记SCOI2017
    BZOJ3810: [Coci2015]Stanovi
    BZOJ4785: [Zjoi2017]树状数组
    「ZJOI2007」「LuoguP1169」棋盘制作(并查集
    「LuoguP4147」 玉蟾宫(并查集
    「LuoguP1402」 酒店之王(最大流
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6648094.html
Copyright © 2011-2022 走看看